</pre><pre name="code" class="html"><!--Atomu's theme-->
<style name="AppThemeWithCustomTitle" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:headerBackground">@color/blue</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowTitleSize">50dp</item>
<item name="android:windowTitleBackgroundStyle">@style/TitleBarStyle</item>
</style>
<style name="TitleBarStyle">
<item name="android:background">@color/blue</item>
</style>
首先改变theme, 去掉默认标题栏
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.activity_picture_flow);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.actionbar_picture_flow);
然后在activity中使用自定义的布局替换标题
新的标题栏中的控件只能从该activity中获取, activity下的fragment无法获取
另一种方法就是在theme中使用noTitle属性去掉标题栏然后完全使用自定义......这样的话按菜单键会报NullPointerE
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_MENU) {
return true;
}
return super.onKeyDown(keyCode, event);
}
xception, 使用这段代码屏蔽掉菜单键