2012-09-28 17 views
11

"done"/"close"アクションモードのテキストの色を設定します。これは私が試したことです:アクションモード閉じるボタンのテキストの色

<item name="android:actionModeCloseButtonStyle">@style/ActionModeCloseButton</item> 
.... 
<style name="ActionModeCloseButton" parent="android:style/Widget.Holo.ActionButton.CloseMode"> 
    <item name="android:textColor">@android:color/white</item> 
</style> 

しかし、効果はありません。

enter image description here

JBに、それは私がActionModeCloseButtonスタイルの親通常のホロをテーマにすることは十分だということに注意してください。そこでは正常に動作します(textColorの設定なしでも)。

アイデア?おかげさまで

答えて

6

まず、テキストビュー「完了」は大きなデバイスでのみ表示されます。 Androidソースのをチェックアウトします。 android:actionModeCloseButtonStyleは、含まれているビューにのみ適用され、imageviewおよびtextviewには適用されません。

幸いなことに、アンドロイドのエンジニアは、一般にアクセス可能な属性を使用して子ビューのスタイルを設定しました。

  • android:actionMenuTextColorを使用して、TextViewのtextColorに変更します。

    以下
    <style name="MyTheme"> 
        <item name="android:actionMenuTextColor">#ff000000</item> 
        <item name="android:actionModeCloseDrawable">@drawable/my_close_drawable</item> 
    </style> 
    

    あなたはレイアウトが構築されてどのように見ることができますlayout-large -folderでのコピーです:

  • 使用android:actionModeCloseDrawableはImageViewの

例の描画可能に変更します。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/action_mode_close_button" 
     android:focusable="true" 
     android:clickable="true" 
     android:paddingStart="8dip" 
     style="?android:attr/actionModeCloseButtonStyle" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_marginEnd="16dip"> 
    <ImageView android:layout_width="48dip" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:scaleType="center" 
       android:src="?android:attr/actionModeCloseDrawable" /> 
    <TextView android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:layout_marginStart="4dip" 
       android:layout_marginEnd="16dip" 
       android:textAppearance="?android:attr/textAppearanceSmall" 
       android:textColor="?android:attr/actionMenuTextColor" 
       android:textSize="12sp" 
       android:textAllCaps="true" 
       android:text="@string/action_mode_done" /> 
</LinearLayout> 
+0

actionMenuTextColorの問題は、「通常の」アクションバー項目の色も変更されることです。 – sergio91pt

+0

変更する正しい項目が 'abs_action_mode_close_item.xml'であり、' abs_action_menu_item_layout.xml'ではないので、これは機能しません。問題は、 'abs_action_mode_close_item.xml'はテキストの色を提供しません:(あなたは簡単にABS用に修正することができますが、それは4.0以前のAndroidsでしか動作しません... – Trinimon

0

アクションモードの閉じるボタンのレイアウトは、テキストビューのための色の属性を提供していないので、カスタムテーマでこの色を設定する方法はありません。私が見つけただけではなくAYは私の派生ActionModeクラスのonPrepareActionMode()方法でテキストの色を上書きすることでした:

@Override 
public boolean onPrepareActionMode(ActionMode mode, Menu menu) { 
    new AsyncTask<Void, Void, Void>() { 
     @Override 
     protected Void doInBackground(Void... none) { 
      try { 
       Thread.sleep(100); 
      } catch (InterruptedException e) { 
      } 
      return null; 
     } 

     @Override 
     protected void onPostExecute(Void none) { 
      if (activity != null) { 
       LinearLayout layout = (LinearLayout) activity 
          .findViewById(R.id.abs__action_mode_close_button); 

       if (layout == null) { 
        int id = Resources.getSystem().getIdentifier(
             "action_mode_close_button", "id", "android"); 
        layout = (LinearLayout) activity.findViewById(id); 
       } 

       if (layout != null && layout.getChildCount() > 1) { 
        TextView label = (TextView) layout.getChildAt(1); 
        if (label != null) label.setTextColor(Color.RED); 
       } 
      } 
     } 
    }.execute(); 

    return false; 
} 

は、2つのデバイスの前と後のAndroid 4.0で働きました。

+0

アンドロイドのバージョンがあなたのコードがそのデバイスで爆破される位置1にTextViewがあります。それをキャスティングする前にinstanceOfチェックを行います。 – MinceMan

関連する問題