2017-05-15 8 views
0

Ich möchte die Standardschriftart der Popup-Menüelemente ändern und von meiner benutzerdefinierten Schriftart für sie verwenden. Wie ist es möglich? Dies ist der Code, den ich für die Erstellung von Popup-Menü verwendet: Verwendung von benutzerdefinierter Schriftart (TTF) DateienSo erstellen Sie ein benutzerdefiniertes PopupMenu mit Schriftarten in Menüelement in Android

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

Ich mag die Schrift meiner Artikel ändern.

+0

i Lösung Ihrer Frage auf diesem Link bitte überprüfen. http://StackOverflow.com/Questions/26957925/how-to-change-popupmenu-items-font –

+1

Mögliche Duplikate von [Wie PopupMenu Elemente Schriftart ändern] (http://StackOverflow.com/questions/26957925/how -zu-ändern-popupmenu-artikel-schriftart) – iled

Antwort

2

Sie können Sie für diese PopupWindow, überprüfen Sie den Code unten:

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