您的位置:首页 > 其它

自定义的title无法填充完全

2014-08-14 08:33 120 查看
昨天有遇到这个问题,很头疼,用了很多方法都没解决。其实很简单:
@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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: