K.Muthu
K.Muthu

Reputation: 1252

issue in custom title bar (android)

when i customize title bar in view by adding a image, i face an issue as the images is not fixed to the edges accurately. I have attached the image where you can see space between the window margin and image added. How to overcome this problem. Below are the code that i have used to customize the title bar. Can anyone help me to fix this issue.

java code :

 requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
 setContentView(R.layout.home_view);
 this.getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
            R.layout.upwindow);

layout code :

  <?xml version="1.0" encoding="utf-8"?>
  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    
  android:orientation="vertical" 
   android:layout_width="fill_parent"
     android:layout_height="32dp">

     <ImageView
         android:id="@+id/imageView1"
         android:layout_width="fill_parent"
         android:layout_height="fill_parent"
         android:background="@drawable/up_bar"
         android:src="@drawable/up_bar" />

<TextView 
    android:id="@+id/pagename"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:text="Sify MyStorage"
    android:textAppearance="?android:attr/textAppearanceMedium" />

</RelativeLayout>

enter image description here

Upvotes: 1

Views: 548

Answers (4)

Android Stack
Android Stack

Reputation: 4314

create style xml in values folder :

<resources>
  <style name="CustomWindowTitleBackground" /> 
  <style name="CustomTheme" parent="android:Theme">
  <item name="android:windowTitleSize">32dp</item> 
 <item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground
 </item> 

</style>
</resources>

then refer it in manifest as :

 android:theme="@style/CustomTheme">

this will solve it .

hope this help .

Upvotes: 1

Samir Mangroliya
Samir Mangroliya

Reputation: 40406

requestWindowFeature(Window.FEATURE_NO_TITLE);

and setBackground to your layout in layout file...

Like,,,

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    
  android:orientation="vertical"  
   android:layout_width="fill_parent"  android:background="@drawable/up_bar" <---Add this
     android:layout_height="32dp">

and Remove imageview from xml

Upvotes: 1

waqaslam
waqaslam

Reputation: 68167

You need to play a little with styling in order to override this behavior. Define a custom theme (style) as below:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="customTitle">
        <item name="android:background">@drawable/up_bar</item>
    </style>
    <style name="myTheme" parent="android:Theme"> 
        <item name="android:windowTitleBackgroundStyle">@style/customTitle</item>
    </style>
</resources>

and then use this theme in your activity by applying android:theme="@style/myTheme" to your desired activity tag in AndroidManifest.xml

Upvotes: 1

WingDev
WingDev

Reputation: 137

Do you have different images for different resolutions? It might be that your image simply does not fit that space, and that you need a larger one. Be careful though, you might run into issues with your app working across different platforms with scaling.

Upvotes: 1

Related Questions