操作栏不接受个人风格不接受、风格、操作、个人

2023-09-12 03:14:07 作者:莫忘初心

我想personilize我的行动吧。我希望它支持API-9及以上 问题是,操作栏不接受改取得styles.xml和物品都没有显示。

I am trying to personilize my action bar. I want it to support API-9 and above the problem is that action bar doesn't accept changed made in styles.xml and items are not shown.

这是我的styles.xml:

this is my 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>

应用程序只是显示没有图标的默认操作栏,我选用既不项目或背景

the application is just showing the default action bar without icon neither items or background that i choosed

推荐答案

该负责人的方式来设置操作栏的颜色与 appcompat-V7 是通过 colorPrimary 的活动主题是:

The official way to set the action bar color with appcompat-v7 is via colorPrimary on the activity theme:

<?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>

至于图标,这已被问了很多,很多次,答案( getSupportActionBar()setDisplayShowHomeEnabled(真); getSupportActionBar()的setIcon(R.drawable.ic_launcher); ),可以通过找到网络搜索 appcompat图标

With regards to the icon, this has been asked many, many times, and the answer (getSupportActionBar().setDisplayShowHomeEnabled(true); and getSupportActionBar().setIcon(R.drawable.ic_launcher);) can be found via Web searches for appcompat icon.