i don Không biết nếu đó là câu trả lời cho câu hỏi của bạn nhưng bạn có thể thử thiết lập màu nền trong bố cục xml như thế này. Nó rất dễ dàng, nó luôn luôn làm việc
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="0xfff00000"
>
<TextView
android:id="@+id/text_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
</LinearLayout>
Bạn cũng có thể làm những việc lạ mắt hơn với hình nền bằng cách tạo ra một tập tin nền xml với gradient mà là mát mẻ và bán trong suốt, và tham khảo nó để sử dụng khác xem ví dụ dưới đây:
bố trí background.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<gradient
android:angle="90"
android:startColor="#f0000000"
android:endColor="#ff444444"
android:type="linear" />
</shape>
</item>
</selector>
bố trí của bạn
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@layout/background"
>
<TextView
android:id="@+id/text_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
</LinearLayout>
Nhìn vào câu trả lời của tôi ở đây http://stackoverflow.com/a/12259787/592042 – David