Android 6.0までの仕様ではContextMenuHeaderに独自にLiniearLayoutを継承したクラスを作成し、そこでテキストヘッダーにテキストをセットして3列の情報を表示していましたが、Android 7.0で使ってみると、ヘッダーテキストに正常にされていません。
なので、7.0で何か変わったというような情報があれば教えてください。
リファレンスと照らし合わせてみましたが、間違えている様子はないようで…。
どうすれば、Android7.0にも対応できるか教えてください。
よろしくお願いします。
独自クラス
java
1public class ContextMenuHeader extends LinearLayout { 2 private TextView title; 3 private TextView title1; 4 private TextView title2; 5 6 private LayoutInflater layoutInflater; 7 8 /*==========================================================================* 9 * Constructor 10 * =========================================================================*/ 11 public ContextMenuHeader(Context context) { 12 super(context); 13 layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 14 View root = layoutInflater.inflate(R.layout.customview_context_menu_header, this, true); 15 title = ((TextView)root.findViewById(R.id.text_header_title)); 16 title1 = ((TextView)root.findViewById(R.id.text_header_title1)); 17 title2 = ((TextView)root.findViewById(R.id.text_header_title2)); 18 } 19 20 /*==========================================================================* 21 * public methods 22 * =========================================================================*/ 23 public void setTitle(String title, String title1, String title2) { 24 this.title.setText(title); 25 this.title1.setText(title1); 26 this.title2.setText(title2); 27 }
呼び出し元
java
1 @Override 2 public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { 3 AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)menuInfo; 4 // タイトル 5 ContextMenuHeader contextMenuHeader = new ContextMenuHeader(getContext()); 6 menu.setHeaderView(contextMenuHeader); 7 8 contextMenuHeader.setTitle("title"); 9 contextMenuHeader.setTitle1("title1"); 10 contextMenuHeader.setTitle2("title2"); 11 12 //メニューボタン 13 menu.add(0, MENU_ITEM_ID_EDIT, 0, R.string.edit); 14 menu.add(0, MENU_ITEM_ID_DELETE, 0, R.string.deleate); 15 16 17 }
xml
1customview_context_menu_header.xml 2<?xml version="1.0" encoding="utf-8"?> 3<RelativeLayout 4 xmlns:android="http://schemas.android.com/apk/res/android" 5 android:layout_width="match_parent" 6 android:layout_height="wrap_content"> 7 8 <LinearLayout 9 android:id="@+id/context_menu_header" 10 android:layout_width="match_parent" 11 android:layout_height="wrap_content" 12 android:layout_centerVertical="true" 13 android:paddingTop="@dimen/text_padding" 14 android:paddingLeft="@dimen/text_padding" 15 android:orientation="vertical"> 16 17 <TextView 18 android:id="@+id/text_header_title" 19 android:layout_width="wrap_content" 20 android:layout_height="wrap_content" 21 android:textSize="@dimen/font_size_title" 22 android:text="title1"/> 23 24 <LinearLayout 25 android:layout_width="match_parent" 26 android:layout_height="wrap_content"> 27 28 <TextView 29 android:id="@+id/label_header_title2" 30 android:layout_width="wrap_content" 31 android:layout_height="wrap_content" 32 android:textSize="@dimen/font_size_subheading" 33 android:text="@string/label_title2"/> 34 35 <TextView 36 android:id="@+id/text_header_title2" 37 android:layout_width="wrap_content" 38 android:layout_height="wrap_content" 39 android:layout_toRightOf="@+id/label_header_" 40 android:paddingLeft="@dimen/text_padding" 41 android:textSize="@dimen/font_size_subheading" 42 android:text="title2"/> 43 44 </LinearLayout> 45 46 <LinearLayout 47 android:layout_width="match_parent" 48 android:layout_height="wrap_content"> 49 50 <TextView 51 android:id="@+id/label_header_title3" 52 android:layout_width="wrap_content" 53 android:layout_height="wrap_content" 54 android:textSize="@dimen/font_size_subheading" 55 android:text="@string/label_title3"/> 56 57 <TextView 58 android:id="@+id/text_header_title3" 59 android:layout_width="wrap_content" 60 android:layout_height="wrap_content" 61 android:layout_toRightOf="@+id/label_header_title3" 62 android:paddingLeft="@dimen/text_padding" 63 android:textSize="@dimen/font_size_subheading" 64 android:text="title3"/> 65 66 </LinearLayout> 67 </LinearLayout> 68</RelativeLayout>
回答1件
あなたの回答
tips
プレビュー