2012-06-25 3 views
0

Description: Je crée une barre de titre personnalisée. Les codes de personnalisation est la suivante:Comment supprimer des espaces dans la barre de titre personnalisée

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> 
code

dans mon activité principale

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

Question: Mon titre personnalisé est ne pas adopter la largeur du parent de remplissage. Il y a des espaces gris à droite et à gauche. comment supprimer ces espaces ??

Répondre

1

le faire de cette façon, il sera résolu:

votre style 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>> 

se réfèrent alors en manifeste comme:

android:theme="@style/CustomTheme"> 

Hope this aide.

+0

Merci beaucoup pour la résolution de mon problème. C'était vraiment très utile. –

Questions connexes