【问题标题】:How to remove spaces in customized Title bar如何删除自定义标题栏中的空格
【发布时间】:2012-06-25 18:39:36
【问题描述】:

描述:我正在创建自定义标题栏。自定义代码如下:

styles.xml

<?xml version="1.0" encoding="UTF-8"?>
<resources>
    <style name="CustomTheme" parent="android:Theme">
        <item name="android:windowTitleSize">50dp</item>
     </style>
</resources>

title.xml

<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relativeLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/customtitlecolor" >

    <Button
        android:id="@+id/about_back"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="9px"
        android:layout_marginTop="6px"
        android:background="@drawable/custombuttoncolor"
        android:paddingBottom="8px"
        android:paddingLeft="8px"
        android:paddingRight="8px"
        android:paddingTop="8px"
        android:text="Back"
        android:textColor="#ffffff" />

    <TextView
        android:id="@+id/about_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="Large Text"
        android:textAppearance="?android:attr/textAppearanceLarge" />

</RelativeLayout>

and finally 

customizedtitlecolor.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
     <gradient android:startColor="#000000" android:endColor="#777777" android:angle="90"/>
     <corners android:radius="7dp"/>
    </shape>

我的主要活动中的代码

requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title);

问题:我的自定义标题没有采用填充父宽度。左右两侧有灰色空间。怎么去掉这些空格??

【问题讨论】:

    标签: android android-titlebar


    【解决方案1】:

    这样做会解决的:

    你的风格 XML:

    <resources> 
     <style name="CustomWindowTitleBackground" /> 
     <style name="CustomTheme" parent="android:Theme"> 
     <item name="android:windowTitleSize">50dp</item>
     <item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground
     </item>
     </style> </resources>>
    

    然后在清单中将其引用为:

     android:theme="@style/CustomTheme">  
    

    希望对您有所帮助。

    【讨论】:

    • 非常感谢您解决了我的问题。这真的很有帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多