如何改变ActionBar颜色?

And*_*mov 4 android android-layout android-actionbar

我怎么能改变ActionBar颜色?我已经实现了这个并且它可以工作但不是我想要的.它只在活动开始后才会改变颜色,因此在应用程序启动后,会显示原始条形颜色,只有一秒钟后我的自定义颜色会被显示.还有其他方法可以解决这个问题吗?提前致谢

....
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);  
    ActionBar actionBar;
    actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#879f38")));
.....
Run Code Online (Sandbox Code Playgroud)

Ahm*_*mad 14

创建主题:

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

<style name="Theme.MyAppTheme.ActionBar" parent="@android:style/Widget.Holo.ActionBar">
    <item name="android:background">#222222</item>
</style>
Run Code Online (Sandbox Code Playgroud)