Android 安卓系统中的popmenu中没有出现图像?

Android 安卓系统中的popmenu中没有出现图像?,android,android-popupwindow,Android,Android Popupwindow,} //这是主要活动 弹出窗口工作正常,但android:icon=“@drawable/ic_launcher”不工作popmenu中没有出现图像/图标,请告诉我如何在android中设置popmenu中的图标。 我是android新手。更改行: public class MainActivity extends Activity { private Button button1; @Override protected void onCreate(Bundle savedInstanceSt

}

//这是主要活动

弹出窗口工作正常,但android:icon=“@drawable/ic_launcher”不工作popmenu中没有出现图像/图标,请告诉我如何在android中设置popmenu中的图标。 我是android新手。

更改行:

public class MainActivity extends Activity {
private Button button1;
@Override
protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);  
          setContentView(R.layout.activity_main);  

          button1 = (Button) findViewById(R.id.button1);  
          button1.setOnClickListener(new OnClickListener() {  

           @Override  
           public void onClick(View v) {  
            //Creating the instance of PopupMenu




            PopupMenu popup = new PopupMenu(MainActivity.this, button1);  
            //Inflating the Popup using xml file  
            popup.getMenuInflater().inflate(R.menu.main, popup.getMenu());  
            //popup.add(0, MENU_QUIT, 0, "Quit").setIcon(R.drawable.menu_quit_icon);

            //registering popup with OnMenuItemClickListener 

            popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {  

             public boolean onMenuItemClick(MenuItem item) { 

              Toast.makeText(MainActivity.this,"You Clicked : " + item.getTitle(),Toast.LENGTH_SHORT).show();  
              return true;  
             }  
            });  

            popup.show();//showing popup menu  
           }  
          });//closing the setOnClickListener method  
         } 


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}


设置showAsAction=“ifRoom”。先生,设置showAsAction=“ifRoom”在标题右侧显示图像,不在弹出菜单中请检查此答案-先生,其在标题栏上给出图标,但不在弹出菜单中,我的弹出菜单操作按钮的点击,然后您必须为该弹出菜单创建另一个xml文件,并将其设置在第行上方。先生,我正在/res/menu/main.xml中创建该文件,但它也不工作。我想知道popmenu是否有任何问题,如上下文菜单等//main.xml我要的是显示弹出菜单的代码..不要在这里发布。。请在你的问题中编辑它。
<RelativeLayout 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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world" />

<Button  
    android:id="@+id/button1"  
    android:layout_width="wrap_content"  
    android:layout_height="wrap_content"  
    android:layout_alignParentLeft="true"  
    android:layout_alignParentTop="true"  
    android:layout_marginLeft="62dp"  
    android:layout_marginTop="50dp"  
    android:text="Show Popup" />  
public class MainActivity extends Activity {
private Button button1;
@Override
protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);  
          setContentView(R.layout.activity_main);  

          button1 = (Button) findViewById(R.id.button1);  
          button1.setOnClickListener(new OnClickListener() {  

           @Override  
           public void onClick(View v) {  
            //Creating the instance of PopupMenu




            PopupMenu popup = new PopupMenu(MainActivity.this, button1);  
            //Inflating the Popup using xml file  
            popup.getMenuInflater().inflate(R.menu.main, popup.getMenu());  
            //popup.add(0, MENU_QUIT, 0, "Quit").setIcon(R.drawable.menu_quit_icon);

            //registering popup with OnMenuItemClickListener 

            popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {  

             public boolean onMenuItemClick(MenuItem item) { 

              Toast.makeText(MainActivity.this,"You Clicked : " + item.getTitle(),Toast.LENGTH_SHORT).show();  
              return true;  
             }  
            });  

            popup.show();//showing popup menu  
           }  
          });//closing the setOnClickListener method  
         } 


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}
android:showAsAction="never"
android:showAsAction="ifRoom"
android:showAsAction="always"