更改操作栏和 activity 其余部分的背景颜色
Change the background color of both the actionbar and the rest of the activity
继续 this question,我想将操作栏(上部窗格)的颜色更改为一种颜色,并将屏幕其余部分的颜色更改为另一种颜色。
我该怎么做?
当我尝试这个时 -
<style name="MyTheme" parent="@style/Theme.AppCompat.Light">
<item name="android:actionBarStyle">@style/MyActionBar</item>
<item name="android:background">#ffffd982</item>
</style>
似乎 'android:background' 定义也覆盖了 actionbarstyle 定义
确实,background
属性取代了 actionBarStyle
属性。但是,需要通过 Activity
的 XML 布局更改整个 Activity
的颜色,使用父级 ViewGroup
的 android:background
属性。 ActionBar
样式对您没有帮助。
在您的 Activity
的根 ViewGroup
中,将 background
属性设置为:
<LinearLayout
android:id="@+id/outermost_viewgroup"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background = "#00FF00"
....
....
编辑:
我刚刚意识到是一个方法:
<item name="android:windowBackground">@color/background</item>
将上述标签添加到您的 ActionBar
样式定义中,以及 colors.xml
文件中的 background
:
<resources>
<color name="background">#00FF00 </color>
</resources>
好了,完成了!
更改 Actionbar 样式 在您的 style.xml 文件中定义样式如下
<style name="AppBaseTheme" parent="android:Theme.Light">
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:actionBarStyle">@style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="@android:style/Widget.ActionBar">
<item name="android:background"><YourColor></item>
<item name="android:titleTextStyle"><Your String Color></item>
</style>
在您的 menifest.xml 文件中使用了您在应用程序标签内的样式,如下所示
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
要设置 activity 的背景颜色,只需在每个 activity 中设置 android:background 属性
<RelativeLayout 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"
android:background="#ff2323"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView2"
android:layout_below="@+id/textView2"
android:layout_marginTop="121dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
我认为这适合你...!
继续 this question,我想将操作栏(上部窗格)的颜色更改为一种颜色,并将屏幕其余部分的颜色更改为另一种颜色。
我该怎么做?
当我尝试这个时 -
<style name="MyTheme" parent="@style/Theme.AppCompat.Light">
<item name="android:actionBarStyle">@style/MyActionBar</item>
<item name="android:background">#ffffd982</item>
</style>
似乎 'android:background' 定义也覆盖了 actionbarstyle 定义
确实,background
属性取代了 actionBarStyle
属性。但是,需要通过 Activity
的 XML 布局更改整个 Activity
的颜色,使用父级 ViewGroup
的 android:background
属性。 ActionBar
样式对您没有帮助。
在您的 Activity
的根 ViewGroup
中,将 background
属性设置为:
<LinearLayout
android:id="@+id/outermost_viewgroup"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background = "#00FF00"
....
....
编辑:
我刚刚意识到是一个方法:
<item name="android:windowBackground">@color/background</item>
将上述标签添加到您的 ActionBar
样式定义中,以及 colors.xml
文件中的 background
:
<resources>
<color name="background">#00FF00 </color>
</resources>
好了,完成了!
更改 Actionbar 样式 在您的 style.xml 文件中定义样式如下
<style name="AppBaseTheme" parent="android:Theme.Light">
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:actionBarStyle">@style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="@android:style/Widget.ActionBar">
<item name="android:background"><YourColor></item>
<item name="android:titleTextStyle"><Your String Color></item>
</style>
在您的 menifest.xml 文件中使用了您在应用程序标签内的样式,如下所示
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
要设置 activity 的背景颜色,只需在每个 activity 中设置 android:background 属性
<RelativeLayout 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"
android:background="#ff2323"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView2"
android:layout_below="@+id/textView2"
android:layout_marginTop="121dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
我认为这适合你...!