Android自定义标题栏填充不满

首先写下怎么自定义标题栏:


1、title.xml创建一个layout的xml


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:background="@drawable/navigationstyle">//注意这个地方,我在这个地方给标题栏设置个了背景图片,发现自定义后的标题栏填充不满;
 
  <TextView
  android:id="@+id/Titletext"   
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"   
        android:layout_centerHorizontal="true"
        android:textSize="21sp"
        android:layout_marginTop="3dp"
        android:textColor="#ffffffff"
        android:textStyle="bold"
        />   
<Button
android:id="@+id/TitleBackBtn"
        android:layout_width="wrap_content"   
        android:layout_height="wrap_content"
        android:background="@drawable/sort"
        android:gravity="center"
        android:layout_marginTop="9dp"
        android:layout_alignParentRight="true"/>
</RelativeLayout>


2、在Activity中进行修改


public class MainPage extends Activity{

private TextView title_text;//title显示的文字

@Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(R.style.CustomTheme);//注意顺序;注意这里的style
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);//title用
setContentView(R.layout.cs);//mainpage
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title);//title用
//======================================================
title_text=(TextView)findViewById(R.id.Titletext);//设置title
title_text.setText("xxx");

}


3、在styles.xml中加上步骤2中的样式

 <!--title  -->
    <style name="CustomTheme" parent="android:Theme.Light">  
    <item name="android:windowTitleSize">40dip</item> 
    <item name="android:windowTitleBackgroundStyle">@drawable/navigationstyle</item>//注意这里,如果不写这个就会填充不满,我测试后得到的结果
    </style>


总结下,俩个地方都要加上这个背景图片。。。。及能填充满了

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值