私のアプリではテーマ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>
しかし、うまくいきません。何かアイデアはありますか?
ActionBar bar = getActionBar();
bar.setBackgroundDrawable(new ColorDrawable("COLOR"));
私はうまくいった ここ 。
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:actionBarStyle">@style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#C1000E</item>
<item name="android:titleTextStyle">@style/AppTheme.ActionBar.TitleTextStyle</item>
</style>
<style name="AppTheme.ActionBar.TitleTextStyle" parent="@android:style/TextAppearance.StatusBar.Title">
<item name="android:textColor">#E5ED0E</item>
</style>
私はそれを使用して解決しました。
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" />
< / resources>。
それがあなたを助けることを願っています。..
もしかしたら、これもお役に立てるかもしれません。ウェブサイトから:
http://nathanael.hevenet.com/android-dev-changing-the-title-bar-background/
まず最初に、アプリケーション(またはアクティビティ)用にカスタムテーマを宣言する必要があります。例えば
<!-- Somewhere in AndroidManifest.xml -->
<application ... android:theme="@style/ThemeSelector">
それから、ホロテーマのある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>
以上です!
ボタン c2
をオンクリックすると、ボタンの背景に応じてアクションバーと通知バーの色をフェッチして変更できます。これが役立つことを願っています。
int color = c2.getBackground()).getColor();
int colorlighter = -color * 40 / 100 + color;
getWindow().setNavigationBarColor(colorlighter);
getWindow().setStatusBarColor(colorlighter);
ActionBar bar = getSupportActionBar();
bar.setBackgroundDrawable(new ColorDrawable(color));
「カラーライター」は、通知バーの色をアクションバーより少し明るく設定するために使用されます。
。
「色」はボタン「c2」の背景色で、それに応じて色を変更します。
Androidのデフォルトのアクションバーを使用する場合。 javaから変更する場合は、前の色を表示してください。
。。
例。 <含む。 laight = "@ layout / app_bar_main"。 android:layout_width = "match_parent"。 android:layout_height = "match_parent" />。
次に、「app_bar_main」内のアクションバーコード。 app_bar_main.xmlの内部に移動し、背景を追加するだけです。
例。
<?xml version="1.0" encoding="utf-8"?>
< android.support.design.widget.CoordinatorLayout xmlns:android = "http://schemas.android.com/apk/res/android"。 xmlns:app = "http://schemas.android.com/apk/res-auto"。 xmlns:tools = "http://schemas.android.com/tools"。 android:layout_width = "match_parent"。 android:layout_height = "match_parent"。 android:fitsSystemWindows = "true"。 tools:context = "hackathon.exponent_it.hacakathon.Activity.MainActivity">。
<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" />
< /android.support.design.widget.CoordinatorLayout>
レイアウト activity_main
がある場合。
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
あなたが置く必要があります。
アクティビティでこのコード。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
toolbar.setBackgroundColor(Color.CYAN);
}