I have a situation where I need to set the background in LinearLayout programmatically.
In my layout, do I set my background using "android: background ="? android: attr / activatedBackgroundIndicator ", but I want to install this programmatically:
<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" >
I tried using:
Drawable d = getActivity().getResources().getDrawable(android.R.attr.activatedBackgroundIndicator); rootLayout.setBackgroundDrawable(d);
But he is falling. Any ideas?
Edit: I also tried using:
rootLayout.setBackgroundResource(android.R.attr.activatedBackgroundIndicator); 10-08 15:23:19.018: E/AndroidRuntime(11133): android.content.res.Resources$NotFoundException: Resource ID
Buffalo
source share