MainActivity的背景颜色没有响应。背景总是呈浅黑色。在这里,我附上了我的样式,主题,清单,MainActivity和themeUtil片段。请看看,告诉我我在哪里做错了。
其实我删除了style ="?pagebackground"给予android:background ="#ffBE80FF"在activity.xml中。背景变为淡紫色,但我再次将其恢复为同样的淡黑色。任何想法为什么会发生。 请帮我解决这个问题。
activity.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
style="?pageBackground"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
android:gravity="center_vertical|center_horizontal"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
>
的manifest.xml
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
apptheme_activated_background_holo_dark.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_activated="true" android:drawable="@drawable/apptheme_list_activated_holo" />
<item android:drawable="@android:color/background_light" />
</selector>
styles.xml
<style name="page_background_pur">
<item name="android:background">@drawable/apptheme_activated_background_holo_dark</item>
</style>
的themes.xml
<style name="AppTheme" parent="Theme.AppCompat">
<item name="colorControlNormal">#ffffff</item>
<item name="colorControlActivated">@color/accent</item>
<item name="colorControlHighlight">@color/accent</item>
<item name="android:textViewStyle">@style/RobotoTextViewStyle</item>
<item name="android:autoCompleteTextViewStyle">@style/RobotoAutoCompleteTextViewStyle</item>
<item name="android:editTextStyle">@style/RobotoEditTextStyle</item>
<item name="android:actionBarStyle">@style/MyActionBar</item>
<item name="pageBackground">@style/page_background_pur</item>
MainActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ThemeUtil.onActivityCreateSetTheme(this);
setContentView(R.layout.activity_main);
}
ThemeUtil.java
/** Set the theme of the activity, according to the configuration. */
public static void onActivityCreateSetTheme(Activity activity) {
switch (sTheme) {
default:
case THEME_PURPLE:
activity.setTheme(R.style.AppTheme);
break;
case NOT_THEME_PURPLE:
/*activity.setTheme(R.style.AppTheme);*/
break;
}
}