我正在尝试使我的动作栏个性化。我希望它支持API-9,上面的问题是,操作栏不接受在styles.xml中所做的更改,并且项目不会显示。
这是我的styles.xml:
<resources>
<style name="AppBaseTheme" parent="Theme.AppCompat.Light"></style>
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:windowBackground">@color/background_window</item>
<item name="android:actionBarStyle">@style/ActionBarStyle</item>
</style>
<style name="ActionBarStyle" parent="@style/Theme.AppCompat.Light.DarkActionBar">
<!--<item name="android:icon">@drawable/ic_launcher</item>-->
<item name="android:background">#ff127d08</item>
</style>
</resources>
应用程序只显示默认的操作栏,没有图标,也没有我选择的项目或背景
发布于 2015-05-26 19:49:38
使用appcompat-v7
设置动作栏颜色的官方方式是通过活动主题上的colorPrimary
:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Apptheme" parent="Theme.AppCompat">
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item>
<item name="colorAccent">@color/accent</item>
</style>
</resources>
关于图标,这已经被问了很多很多次了,the answer (getSupportActionBar().setDisplayShowHomeEnabled(true);
和getSupportActionBar().setIcon(R.drawable.ic_launcher);
)可以通过网络搜索appcompat icon
找到。
发布于 2015-05-26 19:49:02
转到自定义主题,在res-->values文件夹中添加themes.xml
将此代码用于自定义actionbar
themes.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">@style/MyActionBar</item>
<item name="android:actionBarTabStyle">@style/MyActionBarTabs</item>
<!-- Support library compatibility -->
<item name="android:actionBarTabTextStyle">@style/MyTheme.ActionBar.TabText</item>
<item name="android:actionBarTabBarStyle">@style/Divider</item>
</style>
<!-- for Tab divider -->
<style name="Divider" parent="@android:style/Widget.Holo.ActionBar.TabBar">
<item name="android:divider">@android:color/transparent</item> //or use your transparent drawable image
<item name="android:showDividers">middle</item>
<item name="android:dividerPadding">0dp</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">@color/easy</item>
<!-- Support library compatibility -->
<item name="background">@color/easy</item>
</style>
<style name="MyActionBarTabs" parent="@style/Widget.AppCompat.ActionBar.TabView">
<item name="android:background">@drawable/actionbar_tab_indicator</item>
</style>
<style name="MyTheme.ActionBar.TabText" parent="android:style/Widget.Holo.ActionBar.TabText">
<!-- This is a Black text color when selected and a WHITE color otherwise -->
<item name="android:textColor">@color/selector_tab_text</item>
</style>
</resources>
<application
android:allowBackup="true"
android:icon="@drawable/easylogo"
android:label="@string/app_name"
android:largeHeap="true"
android:theme="@style/CustomActionBarTheme" >
<activity
android:name="com.example.Start"
android:label="@string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
https://stackoverflow.com/questions/30457212
复制相似问题