改变背景android标题栏

Tim*_*out 7 android titlebar custom-titlebar

我知道这个问题已被提出,但我无法弄清楚如何让它运作起来.我想改变标题栏的背景.

我不想改变我的应用程序或我的背景风格.

我在这个网站上关注了各种帖子,但似乎都没有给出令人满意的结果.

我认为它就像设置一样简单

<style name="AppTheme" parent="AppBaseTheme">
<item name="android:windowTitleBackgroundStyle">@drawable/backrepeat</item>
</style>
Run Code Online (Sandbox Code Playgroud)

在styles.xml中

然而,这并没有给出任何改变.

对于completness,下面是我的backrepeat文件

<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/bg_diamonds"
android:tileMode="repeat"
android:dither="true" 
/>
Run Code Online (Sandbox Code Playgroud)

和manifest.xml中的代码

<application
android:allowBackup="true"
android:icon="@drawable/maxmm_start_icon"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
Run Code Online (Sandbox Code Playgroud)

Mel*_*cuk 24

您可以在创建活动时使用它.(的onCreate)

ActionBar bar = getActionBar();
//for color
bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#00C4CD")));
//for image
bar.setBackgroundDrawable(getResources().getDrawable(R.drawable.settings_icon));
Run Code Online (Sandbox Code Playgroud)


Ane*_*kur 10

您可以使用此代码更改标题颜色在oncreate()中添加以下行:

ColorDrawable colorDrawable = new ColorDrawable(Color.parseColor("#20a780"));
    getSupportActionBar().setBackgroundDrawable(colorDrawable);
Run Code Online (Sandbox Code Playgroud)