• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Custom title text disappearing but icon showing?

icydash

Newbie
Hey guys. So I'm trying to create a custom titlebar in my app that looks like this (essentially):
title.jpg

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:orientation="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?
 
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();
 
For this I usually just do the following:

Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/header"
        android:layout_width="fill_parent"
        android:layout_height="30dip"
        android:background="@drawable/header_patch9">

  <RelativeLayout
      android:layout_width="fill_parent"
      android:layout_height="fill_parent">

    <ImageView
        android:id="@+id/header_icon"
        android:layout_width="30dip"
        android:layout_height="30dip"
        android:layout_alignParentLeft="true"
        android:background="@drawable/icon" />

    <TextView android:id="@+id/header_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="3dip"
        android:layout_toRightOf="@+id/header_icon"
        android:text="@string/app_name"
        android:textColor="#ffffff"
        android:textSize="16sp"
        android:textStyle="bold"
        android:shadowRadius="2"
        android:shadowDx="0"
        android:shadowDy="0"
        android:shadowColor="#0F0E0D" />

  </RelativeLayout>

</LinearLayout>

include this xml in your main layout:

Code:
    <include layout="@layout/header_bar" />

then in your manifest:

Code:
<activity android:launchMode="singleTop"
             android:name="com.example.MainActivity"
             android:label="@string/app_name"
             android:theme="@android:style/Theme.NoTitleBar">

..key line being (android:theme="@android:style/Theme.NoTitleBar") to remove the regular title bar.
 
Back
Top Bottom