android 新手错误

来源:互联网 发布:js alert 变量 编辑:程序博客网 时间:2024/05/16 19:53

1. Bitmap src = BitmapFactory.decodeResource(getResources(), R.drawable.id);     不要把id写错(比如写成什么控件的了),不然返回null;


2.  设置颜色时。要用Color类,比如Color.BLUE;不要错吧R.color.blue用上,后者只有对应颜色的id,需要getResource().getColor(R.color.blue),这样才是颜色的值。


3. 使用MediaPlayer播放视频时,要注意视频格式,有的即使是MP4视频也不一定能播的。

logcat 报错如下:E/SoftAVC(798): Decoder failed: -2

MediaPlayer error (1, -2147483648)”


4.给布局加背景选择器时,若没有效果,可以加下面参数。

android:clickable="true"


5.自定义属性是必须写对命名空间的包名,否则 No resource identifier found for attribute No

例如:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.mobilesecurity"
    android:versionCode="1"
    android:versionName="1.0测试版本" >

xmlns:myspace="http://schemas.android.com/apk/res/com.mobilesecurity"



0 0
原创粉丝点击