1 今天做android原生短信的二次開發,有個需求需要修改標題欄的顏色,發現覆蓋windowntitle的一些屬性,對於Theme.Light這類主題是有效的,但是對於Theme.Light.holo這類主題有些是無效的,只有覆蓋ActionBar的一些屬性纔可以生效
分析了一下原因,大概是因爲3.0之後加入了AcitonBar,也就是這個時候引入了Theme.Light這些主題,所以這些主題會去找AcitonBar的一些xml屬性來解析。
效果很簡單,修改了一下標題欄顏色
注:MmsHoloTheme是短信的主題
<style name="TitleTheme" parent="MmsHoloTheme">
<item name="android:actionBarStyle">@style/MyActionBarStyle</item>
</style>
<style name="MyActionBarStyle" parent="android:Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#FF0000</item>
</style>
2 ActionBar的一些屬性
import android.os.Bundle;
import android.app.ActionBar;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// setTitle("abc");//設置標題
ActionBar bar = getActionBar(); // 獲取ActionBar的對象
bar.setDisplayHomeAsUpEnabled(false); // 隱藏返回的箭頭
// bar.setHomeButtonEnabled(true);//設置按鈕監聽,通過onOptionsItemSelected()進行監聽,資源ID爲android.R.id.home
// bar.setDisplayShowTitleEnabled(false);//隱藏label
// bar.setDisplayShowHomeEnabled(false);//隱藏home icon
// bar.setTitle("abc");//設置標題
// bar.setSubtitle("efg");//設置子標題
// //不顯示箭頭符號,允許通過onOptionsItemSelected()進行箭頭,但一般的情況下,還是應該給個箭頭提示給用戶。
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
break;
default:
break;
}
return super.onOptionsItemSelected(item);
}
}