2012-05-11 12 views
1

画像を追加して表示するタイトルバーをカスタマイズすると、画像がエッジに正確に固定されないため、問題が発生します。私はウィンドウマージンとイメージの間のスペースを見ることができるイメージを添付しました。この問題を解決する方法。以下は、タイトルバーをカスタマイズするために使用したコードです。誰も私がこの問題を解決するのを助けることができます。カスタムタイトルバー(アンドロイド)の問題

Javaコード:

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

レイアウトコード:

<?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

答えて

1

は値のフォルダにスタイルのXMLを作成します。

<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> 

その後、としてマニフェストにそれを参照してください。これはそれを解決します

android:theme="@style/CustomTheme"> 

このヘルプをご覧ください。

1

あなたは、異なる解像度のための異なるイメージを持っていますか?あなたのイメージが単にそのスペースに合っていない可能性があり、大きなイメージが必要な場合もあります。ただし、スケーラビリティを使用してさまざまなプラットフォームで動作するアプリの問題に遭遇する可能性があります。

1

この動作を無効にするには、スタイリングで少し演奏する必要があります。以下のようにカスタムテーマ(スタイル)を定義します。

<?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> 

をしてからにご希望の活動へandroid:theme="@style/myTheme"タグを適用することによって、あなたの活動にこのテーマを使用したAndroidManifest.xml

1
requestWindowFeature(Window.FEATURE_NO_TITLE); 

とsetBackgroundレイアウトファイルのレイアウトに...

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"> 

およびRemove imageview from xml

関連する問題