Android-Einstellung LinearLayout Hintergrund programmgesteuert
Ich habe eine Situation, in der ich programmgesteuert einen Hintergrund für ein LinearLayout festlegen muss.
In meinem Layout setze ich meinen Hintergrund mit `android: background ="? Android: attr / activateBackgroundIndicator ", aber ich möchte dies programmatisch einstellen:
<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" >
Ich habe versucht mit:
Drawable d = getActivity().getResources().getDrawable(android.R.attr.activatedBackgroundIndicator);
rootLayout.setBackgroundDrawable(d);
Aber es stürzt ab. Irgendwelche Ideen?
Edit: Ich hatte auch versucht mit:
rootLayout.setBackgroundResource(android.R.attr.activatedBackgroundIndicator);
10-08 15:23:19.018: E/AndroidRuntime(11133): android.content.res.Resources$NotFoundException: Resource ID #0x10102fd