我有这样一个情况,需要在LinearLayout中以编程方式设置背景。 在我的布局中,我使用`android:background="?android:attr/activatedBackgroundIndicator"`设置我的背景,但我想以编程方式设置它:
但它崩溃了。有什么想法吗?
编辑:我还尝试使用:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/myLayoutId"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="left|center"
android:paddingBottom="5dip"
android:paddingLeft="5dip"
android:background="?android:attr/activatedBackgroundIndicator"
android:paddingTop="5dip" >
我曾尝试使用:
Drawable d = getActivity().getResources().getDrawable(android.R.attr.activatedBackgroundIndicator);
rootLayout.setBackgroundDrawable(d);
但它崩溃了。有什么想法吗?
编辑:我还尝试使用:
rootLayout.setBackgroundResource(android.R.attr.activatedBackgroundIndicator);
10-08 15:23:19.018: E/AndroidRuntime(11133): android.content.res.Resources$NotFoundException: Resource ID #0x10102fd