小编Raf*_*fiq的帖子

访问xml中的整数资源

我看了这个地方发现了如何在Java类访问整数资源,但对另一资源没有文档.

这是res/values/integers.xml中的Resources

<resources>
     <integer name="input_field_padding" >5</integer>
</resources>
Run Code Online (Sandbox Code Playgroud)

试图访问EditText中的input_field_padding.

<EditText
        android:id="@+id/user_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"    
        android:padding="@integer/input_field_padding" />
Run Code Online (Sandbox Code Playgroud)

但我得到以下例外

java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x10
Run Code Online (Sandbox Code Playgroud)

是否有可能在另一个资源文件中访问它或我错过了什么?

android android-layout android-resources

31
推荐指数
2
解决办法
3万
查看次数

如何从android上的外部存储器中将.gif文件作为InputStream打开

我试图从外部存储(图片目录)加载.gif图像,但我使用以下代码获取'文件未找到异常'.

    InputStream mInputStream = null;
    AssetManager assetManager = getResources().getAssets();
    try {
        mInputStream = assetManager.open(getExternalFilesDir(Environment.DIRECTORY_PICTURES).getAbsolutePath().concat("/01.gif"));          

    } catch (IOException e) {           
        e.printStackTrace();
    }
Run Code Online (Sandbox Code Playgroud)

我也测试过使用手动路径,但得到了相同的异常

mInputStream = assetManager.open("file:///mnt/sdcard/Android/data/com.shurjo.downloader/files/Pictures/01.gif");
Run Code Online (Sandbox Code Playgroud)

在清单文件中有SD卡的读/写权限

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Run Code Online (Sandbox Code Playgroud)

请帮助我如何从外部存储打开文件作为InputStream.提前致谢.

注意:我在模拟器上测试了它,并且在Pictures文件夹下有一个文件01.gif(请参见手册路径).我可以创建目录并将文件放在这些目录中,但无法通过Input Stream访问这些文件.

java android android-emulator

3
推荐指数
1
解决办法
9688
查看次数