3

I set a custom title bar as example http://coderzheaven.com/2011/06/custom-title-bar-in-android/ , every thing works fine but still blue frame appear from original title . The only thing I added is to set the background color to custom title as (android:background="#EECBAD"). How can I remove this blue frame?

###custom_title.xml:

    <RelativeLayout 
     android:id="@+id/RelativeLayout01" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:background="#EECBAD"
     xmlns:android="http://schemas.android.com/apk/res/android">
     <ImageView
     android:layout_width="40dip" 
     android:id="@+id/ImageView01" 
     android:background="@drawable/ic_launcher" 
     android:layout_height="40dip" /> 
    <TextView 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"  
    android:id="@+id/tv" 
    android:text="ELNABIH"
    android:layout_toRightOf="@+id/ImageView01"
    android:textColor="@drawable/red"
    android:textStyle="bold" 
    android:layout_marginLeft="5dip"
    android:layout_marginRight="5dip" />
    </RelativeLayout>

java.class

      package com.test.list;
    import android.app.Activity;
     import android.os.Bundle;
     import android.view.Window;
     import android.widget.TextView;
     public class Tttt extends Activity {  
     @Override 
     public void onCreate(Bundle savedInstanceState) { 
           super.onCreate(savedInstanceState); 
           Boolean customTitleSupported = requestWindowFeature
           (Window.FEATURE_CUSTOM_TITLE); 
           setContentView(R.layout.main);  
           if (customTitleSupported) { 
               getWindow().setFeatureInt
           (Window.FEATURE_CUSTOM_TITLE,R.layout.custom_title); 
               TextView tv = (TextView) findViewById(R.id.tv);  
               tv.setText("name");  


             }
           }
         }
2
  • Please add the code of your layout, where you have modified the background
    – Adinia
    Jan 27, 2012 at 15:46
  • Could you supply the contents of your main layout file? Jan 27, 2012 at 15:48

5 Answers 5

1

Brother, I think this link would help you for sure. I think you'll have to define styles and themes in xml too.

Please create styles.xml & themes.xml in values folder folder under res. Write the following code :

Code for styles.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <resources> <style name="WindowTitleBackground" parent="android:Theme"> 
    <item   name="android:background">@android:color/background_dark</item>
    </style>
    </resources>

Code for themes.xml

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

and insert this in your manifest - android:theme="@style/MyTheme"

0
1

Try to override "android:windowTitleBackgroundStyle".

0
1

If you set the background color for tv TextView, it's because it also has some right and left padding, beside being set to wrap_content:

android:layout_marginLeft="5dip"
android:layout_marginRight="5dip"

You can remove those lines, or try to set the background color for the parent, RelativeLayout01

2
  • already i set background color to relative layout not the textview , update above
    – frozenhill
    Jan 27, 2012 at 19:44
  • Have you also tried to remove the 2 margin attributes? I am sure the styling solution works fine, but in my opinion it was not really necessary for this case.
    – Adinia
    Jan 31, 2012 at 7:55
1

put on style.xml:

<style name="CustomWindowTitleBackground">
        <item name="android:background">@color/LightFacebook</item>
    </style>

on @color/LightFacebook use u custom color.

0
0

You should hide the default title first. You should declare that in AndroidManifest.xml for the activity or set the window params in the java code.

<activity 
    android:name=".MainActivity" 
    android:theme="@android:style/Theme.Black.NoTitleBar" />
1
  • please can you check update above i did it as custom layout not as style or theme , thanks
    – frozenhill
    Jan 27, 2012 at 19:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.