0

I have a problem about the title bar. I want to do 2 buttons in the title bar, but it is seen really bad. First I was thinking I got the button height too big, but when I change the button height nothing is changed. I don't want a custom titlebar and I can't see the text in the button. Can anybody help me?


title bar

My code:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:id="@+id/titleLayout">

    <Button android:id="@+id/done"
            android:layout_width="60dip"
            android:layout_height="38dip"
            android:text="done"
            android:layout_toRightOf="@+id/edit"
           >

    </Button>

    <Button android:id="@+id/edit"
            android:layout_width="60dip"
            android:layout_height="38dip"
            android:text="edit"

            >
    </Button>

    </RelativeLayout>



code nippet:

     final boolean customTitle = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); 
       if ( customTitle ) { Window win = getWindow(); 
  win.setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.title);
DuyguK
  • 4,250
  • 9
  • 33
  • 46
  • Did you try to use not fixed size of buttons, but `WRAP_CONTENT` instead of? – teoREtik Dec 15 '11 at 09:14
  • Could you give a code snippet where you set your layout into title? – teoREtik Dec 15 '11 at 09:17
  • Sure.my xml file name is title.I call in my code with this: final boolean customTitle = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); if ( customTitle ) { Window win = getWindow(); win.setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.title); } – DuyguK Dec 15 '11 at 09:19
  • It would be better for everyone if you add this snippet as the edition of your post – teoREtik Dec 15 '11 at 09:24

3 Answers3

0

Jsut try to make your RelativeLayout's height WRAP_CONTENT

teoREtik
  • 7,886
  • 15
  • 46
  • 65
  • It looks like that TitleBar sizes are fixed and they don't change depending on bar's content. – teoREtik Dec 15 '11 at 09:58
  • What will i do have you got any suggestion? – DuyguK Dec 15 '11 at 13:04
  • 1
    Define two own – teoREtik Dec 15 '11 at 14:04
  • I dont want to custom titlebar.Why can not add good looking button?If we can add we can do good looking i think.But i really thanks for reply @teoRetik – DuyguK Dec 15 '11 at 16:18
  • If you would look at Android source code you will see, that there is only one implementation of `Window` class - `PhoneWindow` and only this class use `setFeatureInt` correctly. Other classes only inflate the space of title but not difine it's sizes. – teoREtik Dec 20 '11 at 05:46
0

You can do like this. Before initializing setContentView(), write this line of code

requestWindowFeature(Window.FEATURE_NO_TITLE);

Then in your layout XML file, include your custom title bar like this.

<include layout="@layout/title" android:id="@+id/title"/>
0

What about just using Text and formatting the background, edges, etc. to make it look like a button. I would try using a TextView, wrap_content and then play with paddings, and background.


<RelativeLayout xmlns:android=" http://schemas.android.com/apk/res/android " 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:id="@+id/titleLayout"> 

<TextView 
    android:id="@+id/doneBtn" 
    android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_alignParentLeft="true" 
android:layout_alignParentTop="true" 
android:layout_marginLeft="10dip" 
android:layout_marginRight="10dip" 
android:background="@drawable/bluebutton" 
android:text="Done" 
android:textStyle="bold" 
android:textColor="#FFFFFFFF" 
/> 
</RelativeLayout> 

and then in your @drawable/bluebutton.xml 
<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android=" http://schemas.android.com/apk/res/android "> 
<item> 
<shape> 
    <gradient 
        android:startColor="#FFBBDDFF" 
        android:centerColor="#FF191990" 
        android:endColor="#FF0000FF" 
        android:angle="270" /> 

  </shape> 
 </item> 
</selector> 

Look at this link for more details I hope it helps... Standard Android Button with a different color

Community
  • 1
  • 1
Huasillo
  • 71
  • 1
  • 6