2017-05-15 4 views
0

ポップアップメニュー項目のデフォルトフォントを変更し、カスタムフォントから使用したいと思っています。 これは私がポップアップメニューを作成するために使用されるコードです:Androidのメニュー項目にフォントを使用してカスタムPopupMenuを作成する方法

<item 
    android:id="@+id/Setting" 
    android:title="Setting"/> 
<item 
    android:id="@+id/About" 
    android:title="About"/> 
<item 
    android:id="@+id/Help" 
    android:title="Help"/> 

私はカスタム書体(TTF)ファイルを使用して私の項目の書体を変更したいです。

+0

を私は確認してくださいこのリンクをあなたの質問の解決策を見つけました。 http://stackoverflow.com/questions/26957925/how-to-change-popupmenu-items-font –

+1

[PopupMenu items fontを変更する方法](http://stackoverflow.com/questions/26957925/how)の可能な複製-to-change-popupmenu-items-font) – iled

答えて

2

あなたはこのためにPopupWindowことができ、以下のコードをチェック:

pop_layout.xml

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:tools="http://schemas.android.com/tools" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      tools:context=".MainActivity" 
      android:orientation="vertical" 
      android:padding="5dp"> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentLeft="true" 
       android:layout_marginTop="22dp" 
       android:text="Item 1" 
       android:id="@+id/one" 
       android:textAppearance="?android:attr/textAppearanceMedium" /> 
      <TextView 

       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentLeft="true" 
       android:id="@+id/two" 
       android:layout_marginTop="22dp" 
       android:text="Item 2" 
       android:textAppearance="?android:attr/textAppearanceMedium" /> 
      <TextView 
       android:id="@+id/three" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentLeft="true" 
       android:layout_marginTop="22dp" 
       android:text="Item 3" 
       android:textAppearance="?android:attr/textAppearanceMedium" /> 
      <TextView 
       android:id="@+id/four" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentLeft="true" 
       android:layout_marginTop="22dp" 
       android:text="Item 4" 
       android:textAppearance="?android:attr/textAppearanceMedium" /> 

     </LinearLayout> 

PopupWindow:

    LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
        final View popupView = layoutInflater.inflate(R.layout.pop_layout, null); 


        TextView one = (TextView)popupView.findViewById(R.id.one); 
        TextView two = (TextView)popupView.findViewById(R.id.two); 
        TextView three = (TextView)popupView.findViewById(R.id.three); 
        TextView four = (TextView)popupView.findViewById(R.id.four); 
        // Do your customised stuff 

        PopupWindow popupWindow = new PopupWindow(
          popupView, 
          ViewGroup.LayoutParams.WRAP_CONTENT, 
          ViewGroup.LayoutParams.WRAP_CONTENT); 

        popupWindow.setBackgroundDrawable(new BitmapDrawable()); 
        popupWindow.setOutsideTouchable(true); 
        popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() { 
         @Override 
         public void onDismiss() { 
          //TODO do sth here on dismiss 
         } 
        }); 
        popupWindow.showAsDropDown(view);// your view instance in which click you want to show menu 
関連する問題