描述:我正在创建自定义标题栏。自定义代码如下:
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);
问题:我的自定义标题未采用填充父级宽度。左右两侧有灰色空间。如何删除这些空格??
答案 0 :(得分: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">
希望得到这个帮助。