2011年7月2日土曜日

Honeycomb 3.0 で xml 指定だと tileMode が効かない

ActionBar をカスタマイズしようと思って、

res/drawable/actionbar_bg.xml
  1. <bitmap xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     android:src="@drawable/bg2"  
  3.     android:tileMode="repeat" />  


res/values/styles.xml
  1. <resources>  
  2.     <style name="MyTheme" parent="@android:style/Theme.Holo.Light">  
  3.         <item name="android:windowBackground">@drawable/bg</item>  
  4.         <item name="android:actionBarStyle">@style/MyActionBar</item>  
  5.           
  6.     </style>  
  7.       
  8.     <style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">  
  9.         <item name="android:titleTextStyle">@style/MyActionBarTitle</item>  
  10.         <item name="android:subtitleTextStyle">@style/MyActionBarSubTitle</item>  
  11.         <item name="android:background">@drawable/actionbar_bg</item>  
  12.     </style>  
  13.       
  14.     <style name="MyActionBarTitle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">  
  15.         <item name="android:textColor">#fff</item>      
  16.     </style>  
  17.   
  18.     <style name="MyActionBarSubTitle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Subtitle">  
  19.         <item name="android:textColor">#fff</item>      
  20.     </style>  
  21. </resources>  


としたら、リピートされなくて引き伸ばしたようになってしましました。
調べたら、

[Honeycomb / Android 3.0] ActionBar background image - Stack Overflow -

に書いてありました。

honeycomb / Android 3.0 の既知のバグだそうです。3.1 では直ってるのかな?

現状での解決方法はコードから指定する。です。

Activity の onCreate() で

  1. final ActionBar actionBar = getActionBar();   
  2. BitmapDrawable background = (BitmapDrawable)getResources().getDrawable(R.drawable.bg2);  
  3. background.setTileModeXY(android.graphics.Shader.TileMode.REPEAT, android.graphics.Shader.TileMode.REPEAT);   
  4. actionBar.setBackgroundDrawable(background);  


のように指定するとちゃんとリピートされます。

0 件のコメント:

コメントを投稿