2012-05-10 12 views
6

Tôi có một ActionBarSherlock trên biểu mẫu của tôi. Tôi đang đọc thông tin về phong cách khi chạy. Một trong những phần của phong cách là màu nền của ActionBar. Làm thế nào tôi có thể thay đổi điều này khi chạy? Màu sắc có thể là bất kỳ giá trị RGB nào.Thay đổi màu nền của ActionBarSherlock lập trình

+0

Hãy xem http://stackoverflow.com/questions/10064411/change-actionbarsherlock-background-color – sonida

Trả lời

8

Có lẽ điều này giúp đỡ: How to set title color in ActionBarSherlock? qua phong cách hoặc getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.ad_action_bar_gradient_bak)); qua lập trình

Với chủ đề

// add theme in app 
<application android:theme="@style/MainTheme"></application> 

// MainTheme 
<style name="MainTheme" parent="Theme.Sherlock.Light.DarkActionBar">  
</style> 

// MainThemeGreen 
<style name="MainThemeGreen" parent="Theme.Sherlock.Light.DarkActionBar"> 
    <item name="android:actionBarStyle">@style/MainTheme.ActionBarStyle</item>   
</style> 

// ActionBar 
<style name="MainTheme.ActionBarStyle" parent="Widget.Sherlock.Light.ActionBar"> 
    <item name="android:background">@drawable/bg_green_actionbar</item> 
    <item name="android:titleTextStyle">@style/MainTheme.ActionBar.TitleTextStyle</item> 
</style> 

// Text style 
<style name="MainTheme.ActionBar.TitleTextStyle" parent="TextAppearance.Sherlock.Widget.ActionBar.Title"> 
    <item name="android:textColor">@color/White</item> 
</style> 

// bg_green_actionbar.xml 
<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" > 
    <item> 
     <shape> 
      <solid android:color="#ff74af3b" /> 
     </shape> 
    </item> 
</layer-list> 

Sau này bạn có thể thay đổi Theme trên ruồi: setTheme (R.styles.MainThemeGreen);

+0

Bạn vẫn đang chỉ định tài nguyên có thể vẽ cục bộ. Tôi cần phải làm điều đó cho bất kỳ màu nào được trình bày cho tôi từ một dịch vụ web. –

+0

Tôi thấy bản chỉnh sửa mới của bạn nhưng tôi không làm theo cách này. Sau khi ứng dụng bắt đầu, tôi gọi một dịch vụ web và nó trả về một màu. Nói là # 123456. Làm cách nào để áp dụng điều đó cho mã # FF74af3b cứng của bạn? –

6

Một cách:

mSupportActionBar = getSupportActionBar(); 
mSupportActionBar.setBackgroundDrawable(new ColorDrawable(0xff123456)); 

nơi 0xff123456 là cần ARGB số nguyên của bạn.

5

tôi chỉ sử dụng dưới đây Mã

getSupportActionBar().setBackgroundDrawable(new 
    ColorDrawable(Color.parseColor("#00853c"))); 

nó thay đổi màu sắc bg. Hy vọng nó giúp.