昨天有遇到这个问题,很头疼,用了很多方法都没解决。其实很简单:
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
setTheme(R.style.CustomTheme); //使用自定义的title样式
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); //使用自定义的title
setContentView(R.layout.setting_common);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_main2);
//注意:::上面三行一定不能打乱顺序!!!!
initTitle();
}
private void initTitle() {
// TODO Auto-generated method stub
((TextView)this.findViewById(R.id.titlemain_tv_title2)).setText(
"关于我们");
((ImageView)this.findViewById(R.id.titlemain_iv_titleback2)).setOnClickListener(this);
TextView tv_cancel = (TextView)this.findViewById(R.id.titlemain_tv_titleright2);
tv_cancel.setText("完成");
tv_cancel.setOnClickListener(this);
}
注意哦,在style.xml里面一点要有:
<style name="CustomTheme" parent="android:Theme">
<item name="android:windowTitleSize">60dip</item>
<item name="android:padding">0sp</item> <!-- 使自定义的title完全填充 -->
</style>
<span style="color:#ff0000;"> <item name="android:padding">0sp</item> <!-- 使自定义的title完全填充 --></span>