2014-04-19 5 views
1

J'ai créé une barre de titre personnalisée avec les éléments suivants.Android: Titre non affiché dans la barre de titre personnalisée avec affichage ListAdapter personnalisé

myapptitle.xml

<?xml version="1.0" encoding="utf-8"?> 
<TextView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/myTitle" 
    android:text="@string/app_name" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:textColor="@color/titletextcolor" 
    android:textSize="14sp" 
    android:layout_gravity="top" 
    /> 

themes.xml

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <style name="customTheme" parent="android:Theme"> 
     <item name="android:windowTitleBackgroundStyle">@style/WindowTitleBackground</item> 
     <item name="android:windowTitleSize">40dip</item> 
    </style> 
</resources> 

manifext.xml

<application 
     android:label="@string/app_name" 
     android:theme="@style/customTheme" > 
..... 

J'ai créé un cu stomList adapter et une mise en page pour celle-là comme celle ci-dessous.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" > 

    <ImageView 
     android:id="@+id/icon" 
     android:layout_width="22dip" 
     android:layout_height="22dip" 
     android:layout_marginLeft="4dip" 
     android:layout_marginRight="10dip" 
     android:layout_marginTop="4dip" 
     android:contentDescription="@string/app_msg_title" 
     android:src="@drawable/logo_small" > 
    </ImageView> 

    <TextView 
     android:id="@+id/msgDate" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:textSize="14sp" 
     /> 

    <TextView 
     android:id="@+id/msgTitle" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:textSize="14sp" /> 

    <TextView 
     android:id="@+id/label" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@+id/label" 
     android:textSize="12sp" > 
    </TextView> 

</LinearLayout> 

Dans mon activité de liste, j'ai donné le code ci-dessous à la méthode onCreate.

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

Mais de toute façon, lors de l'exécution de l'application, je reçois la barre de titre sans aucun texte. Dans mon string.xml pour app_name j'ai Mes notifications comme texte.

Appréciez tout votre temps et aidez-nous.

Edité styles.xml

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <style name="WindowTitleBackground"> 
     <item name="android:background">@color/titlebackgroundcolor</item> 
    </style> 
</resources> 
+0

fournissent l'ensemble du fichier style.xml. – Riser

+0

Salut Achille, nous y voilà. \t ​​ \t \t @ couleur/titlebackgroundcolor \t Jerokdeep

+0

où allons-nous? .. – Riser

Répondre

0

Changer votre style.xml comme ci-dessous:

<resources> 
     <style name="CustomWindowTitleBarBG"> 
       <item name="android:background">#323331</item> 
     </style> 

     <style name="TitleBarTheme" parent="android:Theme"> 
      <item name="android:windowTitleSize">35dip</item> 
<item name="android:windowTitleBackgroundStyle">   @style/CustomWindowTitleBarBG</item> 
     </style> 
</resources> 

Alors

Dans le fichier manifeste, utilisez TitleBarTheme dans la balise d'application et pour l'utilisation de l'activité comme ci-dessous:

android:theme="@android:style/Theme.NoTitleBar" 

et en classe d'activité utiliser votre code qui est:

requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); 
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, 
       R.layout.myapptitle); 
+0

Fait les changements, mais en obtenant l'exception suivante tout en élevant l'activité. java.lang.RuntimeException: Impossible de démarrer l'activité ComponentInfo {com.sas.mobi.pushclient/com.sas.mobi.pushclient.MessagesListActivity}: android.util.AndroidRuntimeException: Vous ne pouvez pas combiner des titres personnalisés avec d'autres fonctionnalités de titre – Jerokdeep

+0

Essayez d'ajouter cette ligne dans la première partie du code. false Riser

+0

Travaux Merci. !!! – Jerokdeep

Questions connexes