1. Download our Official Android App: Forums for Android!

Apps Custom title text disappearing but icon showing?

Discussion in 'Android Development' started by icydash, Jun 8, 2011.

  1. icydash

    icydash Newbie
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    12
    Joined:
    Jun 8, 2011

    Jun 8, 2011
    12
    0
    15
    Hey guys. So I'm trying to create a custom titlebar in my app that looks like this (essentially):
    [​IMG]
    For some reason, the icon shows up, but not the title text. It's really weird. For a split second you see the title text, but then it disappears and only the icon shows in the title.

    My code is as follows:

    ==========================window_title.xml==========================

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:eek:rientation="horizontal"
    android:layout_width="60px"
    android:layout_height="60dip"
    android:gravity="center_vertical"
    android:paddingLeft="5dip">

    <ImageView
    android:id="@+id/header"
    android:src="@drawable/icon"
    android:layout_width="50px"
    android:layout_height="wrap_content"/>

    </LinearLayout>



    ==========================custom_styles.xml==========================
    <?xml version="1.0" encoding="utf-8"?>
    <resources>
    <style name="CustomWindowTitleText" parent="android:TextAppearance.WindowTitle">
    <item name="android:textSize">20dip</item>
    <item name="android:textColor">#FFFFFF</item>
    <item name="android:textStyle">bold|italic</item>
    <item name="android:paddingLeft">20dip</item>
    </style>

    <style name="CustomWindowTitle" parent="android:WindowTitle">
    <item name="android:textAppearance">@style/CustomWindowTitleText</item>
    <item name="android:shadowDx">0</item>
    <item name="android:shadowDy">0</item>
    <item name="android:shadowRadius">5</item>
    <item name="android:shadowColor">#1155CC</item>
    <item name="android:paddingLeft">100px</item>
    </style>

    <style name="CustomTheme" parent="android:Theme">
    <item name="android:windowTitleSize">60dip</item>
    <item name="android:windowTitleStyle">@style/CustomWindowTitle</item>
    </style>
    </resources>



    ==========================AdroidManifest.xml==========================
    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.app.uNear"
    android:versionCode="1"
    android:versionName="1.0">
    <uses-sdk android:minSdkVersion="10" />

    <application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@style/CustomTheme">
    <activity android:name=".uNear"
    android:label="@string/app_name">
    <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    </activity>

    </application>
    </manifest>



    ===========relevant part of java source code==============
    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    setContentView(R.layout.main);
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);







    Anyone have any idea why this is happening?
     

    Advertisement

  2. XMight

    XMight Lurker
    Rank:
    None
    Points:
    5
    Posts:
    1
    Joined:
    Oct 7, 2011

    Hi, I don't know if you solved it or not, but I faced a similar issue. The solution in my case was to verify on what activity I set the custom title. I had a tabhost activity, in which I was using the main instance to set titles for other activities inside tabs, and one of them was starting another activity, but I was setting the title to the main activity.
    Also, check that u added the action to set the title in onResume();
     
  3. steve

    steve Developer
    Administrator
    Rank:
     #42
    Points:
    573
    Posts:
    1,086
    Joined:
    Apr 19, 2011

    Apr 19, 2011
    1,086
    1,177
    573
    Male
    Android Developer
    York, PA
    For this I usually just do the following:

    Code (Text):
    1.  
    2. <?xml version="1.0" encoding="utf-8"?>
    3. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    4.         android:id="@+id/header"
    5.         android:layout_width="fill_parent"
    6.         android:layout_height="30dip"
    7.         android:background="@drawable/header_patch9">
    8.  
    9.   <RelativeLayout
    10.       android:layout_width="fill_parent"
    11.       android:layout_height="fill_parent">
    12.  
    13.     <ImageView
    14.         android:id="@+id/header_icon"
    15.         android:layout_width="30dip"
    16.         android:layout_height="30dip"
    17.         android:layout_alignParentLeft="true"
    18.         android:background="@drawable/icon" />
    19.  
    20.     <TextView android:id="@+id/header_title"
    21.         android:layout_width="wrap_content"
    22.         android:layout_height="wrap_content"
    23.         android:paddingLeft="3dip"
    24.         android:layout_toRightOf="@+id/header_icon"
    25.         android:text="@string/app_name"
    26.         android:textColor="#ffffff"
    27.         android:textSize="16sp"
    28.         android:textStyle="bold"
    29.         android:shadowRadius="2"
    30.         android:shadowDx="0"
    31.         android:shadowDy="0"
    32.         android:shadowColor="#0F0E0D" />
    33.  
    34.   </RelativeLayout>
    35.  
    36. </LinearLayout>
    37.  
    include this xml in your main layout:

    Code (Text):
    1.  
    2.     <include layout="@layout/header_bar" />
    3.  
    then in your manifest:

    Code (Text):
    1.  
    2. <activity android:launchMode="singleTop"
    3.              android:name="com.example.MainActivity"
    4.              android:label="@string/app_name"
    5.              android:theme="@android:style/Theme.NoTitleBar">
    6.  
    ..key line being (android:theme="@android:style/Theme.NoTitleBar") to remove the regular title bar.
     

Share This Page

Loading...