18

アプリでアプリのテーマを使用していTheme.Blackます。このテーマでは、アクション バーは灰色です。アクションバーの色を変更するにはどうすればよいですか? これは私の試みです:

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">

    <style name="mytheme" parent="@android:style/Theme.Black" >

    </style>
    <style name="Widget.MyApp.ActionBar" parent="@android:style/Widget.ActionBar">
        <item name="android:background">@android:color/black</item>
    </style>



</resources>

しかし、うまくいきません。何か案は?

4

9 に答える 9

7
 ActionBar actionBar;

 actionBar = getActionBar(); 
 ColorDrawable colorDrawable = new ColorDrawable(Color.parseColor("#93E9FA"));     
 actionBar.setBackgroundDrawable(colorDrawable);
于 2014-12-09T07:13:04.093 に答える
2

res/values/styles.xml ファイルに移動し、xml ファイルを編集して xml ファイルの色を変更するだけです。サンプル コードは次のとおりです。

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->

// 以下のコードは、アクションバーの色を変更するためのものです

    <item name="colorPrimary">"type your color code here. eg:#ffffff"</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

それがあなたを助けることを願っています...

于 2017-01-04T10:26:57.713 に答える
1

Androidのデフォルトのアクションバーを使用している場合。Java から変更すると、以前の色が表示されることがあります。

ここに画像の説明を入力

次に、「app_bar_main」内のアクション バー コード。app_bar_main.xml に移動して、Background を追加します。

<?xml version="1.0" encoding="utf-8"?>

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="#33691e"   <!--use your color -->
        app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main1" />

于 2016-04-07T02:02:13.500 に答える
0

多分これもあなたを助けることができます。それはウェブサイトからです:

http://nathanael.hevenet.com/android-dev-ching-the-title-bar-background/

まず最初に、アプリケーション (または必要に応じてアクティビティ) に対してカスタム テーマを宣言する必要があります。みたいな…</p>

<!-- Somewhere in AndroidManifest.xml -->
<application ... android:theme="@style/ThemeSelector">

次に、Holo テーマを使用する API バージョンと使用しない API バージョンの 2 つのケースのカスタム テーマを宣言します。古いテーマでは windowTitleBackgroundStyle 属性をカスタマイズし、新しいテーマでは ActionBarStyle をカスタマイズします。

<!-- res/values/styles.xml -->
<?xml version="1.0" encoding="utf-8"?>
<resources>

    <style name="ThemeSelector" parent="android:Theme.Light">
        <item name="android:windowTitleBackgroundStyle">@style/WindowTitleBackground</item>
    </style>

    <style name="WindowTitleBackground">     
        <item name="android:background">@color/title_background</item>
    </style>

</resources>

<!-- res/values-v11/styles.xml -->
<?xml version="1.0" encoding="utf-8"?>
<resources>

    <style name="ThemeSelector" parent="android:Theme.Holo.Light">
        <item name="android:actionBarStyle">@style/ActionBar</item>
    </style>

    <style name="ActionBar" parent="android:style/Widget.Holo.ActionBar">     
        <item name="android:background">@color/title_background</item>
    </style>

</resources>

それでおしまい!

于 2013-08-09T14:12:44.143 に答える