android开发错误经验总结

TextView:

1.textView.setText();参数如果直接传int类型,ide不会显示错误。但是运行会报错。

布局渲染:

1.

<View
android:background="#E5E5E5"
android:layout_width="match_parent"
android:layout_height="1dp"/>
划一条横线的时候记得View要大写。否则报错。

2.在studio中定义drawable资源及获取方法:
<string-array name="actions_images">  
    <item>@drawable/pencil1</item>  
    <item>@drawable/pencil2</item>  
    <item>@drawable/pencil3</item>  
    <item>@drawable/pencil4</item>  
    <item>@drawable/pencil5</item>  
    <item>@drawable/pencil6</item>  
</string-array> 

获取方法:

TypedArray ar = context.getResources().obtainTypedArray(R.array.actions_images);  
int len = ar.length();       
int[] resIds = new int[len];       
for (int i = 0; i < len; i++)       
    resIds[i] = ar.getResourceId(i, 0);  
  
ar.recycle();    

不能够定义为Integer。这样获取不到。

原文地址:https://www.cnblogs.com/jdhdevelop/p/10768866.html