• <legend id='nadwG'><style id='nadwG'><dir id='nadwG'><q id='nadwG'></q></dir></style></legend>
      <bdo id='nadwG'></bdo><ul id='nadwG'></ul>
    <i id='nadwG'><tr id='nadwG'><dt id='nadwG'><q id='nadwG'><span id='nadwG'><b id='nadwG'><form id='nadwG'><ins id='nadwG'></ins><ul id='nadwG'></ul><sub id='nadwG'></sub></form><legend id='nadwG'></legend><bdo id='nadwG'><pre id='nadwG'><center id='nadwG'></center></pre></bdo></b><th id='nadwG'></th></span></q></dt></tr></i><div id='nadwG'><tfoot id='nadwG'></tfoot><dl id='nadwG'><fieldset id='nadwG'></fieldset></dl></div>

        <small id='nadwG'></small><noframes id='nadwG'>

        <tfoot id='nadwG'></tfoot>

      1. 如何在android溢出按钮上更改弹出菜单的位置?

        时间:2024-04-14
      2. <i id='fUpRR'><tr id='fUpRR'><dt id='fUpRR'><q id='fUpRR'><span id='fUpRR'><b id='fUpRR'><form id='fUpRR'><ins id='fUpRR'></ins><ul id='fUpRR'></ul><sub id='fUpRR'></sub></form><legend id='fUpRR'></legend><bdo id='fUpRR'><pre id='fUpRR'><center id='fUpRR'></center></pre></bdo></b><th id='fUpRR'></th></span></q></dt></tr></i><div id='fUpRR'><tfoot id='fUpRR'></tfoot><dl id='fUpRR'><fieldset id='fUpRR'></fieldset></dl></div>

            • <bdo id='fUpRR'></bdo><ul id='fUpRR'></ul>

                • <legend id='fUpRR'><style id='fUpRR'><dir id='fUpRR'><q id='fUpRR'></q></dir></style></legend>
                • <tfoot id='fUpRR'></tfoot>

                  <small id='fUpRR'></small><noframes id='fUpRR'>

                    <tbody id='fUpRR'></tbody>
                  本文介绍了如何在android溢出按钮上更改弹出菜单的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我只是想在 Gmail 应用中实现与弹出菜单相同的功能,锚定在右上角的溢出按钮上.为此,我使用了与 google android 教程相同的代码 Android 弹出菜单,但对我来说,在操作栏边缘的顶部显示弹出菜单,而不是在其下方.如果您注意到 gmail 溢出的弹出菜单,您会看到弹出菜单发生在操作栏的边缘.

                  I just like to implement somethings same as popup menu in the Gmail app, anchored to the overflow button at the top-right. for that I used the same code as google tutorial for android Android popup menu, but for me show pop menu on top of edge of actionbar not under that. If you notice on pop menu of gmail overflow you saw that popmenu take place at edge of actionbar.

                  这是我用于弹出菜单的 xml:

                  This is the xml that I used for popup menu:

                  <menu xmlns:android="http://schemas.android.com/apk/res/android" >
                  
                      <item
                          android:id="@+id/item1"
                          android:title="lablab"/>
                      <item
                          android:id="@+id/item2"
                          android:title="lablab"/>
                  
                  </menu>
                  

                  以下是我的活动:

                  public void showFontSetting(View view) {
                      PopupMenu popup = new PopupMenu(this, view);
                      MenuInflater inflater = popup.getMenuInflater();
                      inflater.inflate(R.menu.menu, popup.getMenu());
                      popup.show();
                  
                      popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                  
                          @Override
                          public boolean onMenuItemClick(MenuItem item) {
                          // TODO Auto-generated method stub
                  
                              switch (item.getItemId()) {
                                  case R.id.item1:
                                      Toast.makeText(Index.this,
                                          "You Clicked : " + item.getTitle(),
                                      Toast.LENGTH_SHORT).show();
                                      break;
                                  case R.id.item2:
                                      break;
                              }
                              return true;
                          }
                      });
                  }
                  

                  推荐答案

                  将以下代码添加到您的活动中:

                  Add the following piece of code to your activity:

                  PopupWindow popupwindow_obj; // create object
                  
                  popupwindow_obj=popupDisplay();  // initialize in onCreate()
                  
                  popupwindow_obj.showAsDropDown(clickbtn,-40, 18); // where u want show on view click event
                  
                  public PopupWindow popupDisplay() { // disply designing your popoup window
                      final PopupWindow popupWindow = new PopupWindow(this); // inflet your layout or diynamic add view
                  
                      View view; 
                  
                      LayoutInflater inflater = (LayoutInflater)   getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
                  
                      view = inflater.inflate(R.layout.mylayout, null);
                  
                      Button item = (LinearLayout) view.findViewById(R.id.button1);
                  
                      popupWindow.setFocusable(true);
                      popupWindow.setWidth(WindowManager.LayoutParams.WRAP_CONTENT);
                      popupWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
                      popupWindow.setContentView(view);
                  
                      return popupWindow;
                  }
                  

                  res/layout 目录中创建一个 XML 并命名为 mylayout.xml

                  Create an XML in res/layout directory and name it mylayout.xml

                  <LinearLayout
                          android:layout_width="fill_parent"
                          android:layout_height="wrap_content"
                          android:orientation="horizontal" >
                  
                          <Button
                              android:id="@+id/button1"
                              android:layout_width="wrap_content"
                              android:layout_height="wrap_content"
                              android:text="Window test" />
                  </LinearLayout>
                  

                  这篇关于如何在android溢出按钮上更改弹出菜单的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:弹出窗口以在片段中显示一些东西 下一篇:如何更改弹出项目宽度大小?

                  相关文章

                  • <bdo id='3aUCa'></bdo><ul id='3aUCa'></ul>
                  1. <legend id='3aUCa'><style id='3aUCa'><dir id='3aUCa'><q id='3aUCa'></q></dir></style></legend>

                  2. <i id='3aUCa'><tr id='3aUCa'><dt id='3aUCa'><q id='3aUCa'><span id='3aUCa'><b id='3aUCa'><form id='3aUCa'><ins id='3aUCa'></ins><ul id='3aUCa'></ul><sub id='3aUCa'></sub></form><legend id='3aUCa'></legend><bdo id='3aUCa'><pre id='3aUCa'><center id='3aUCa'></center></pre></bdo></b><th id='3aUCa'></th></span></q></dt></tr></i><div id='3aUCa'><tfoot id='3aUCa'></tfoot><dl id='3aUCa'><fieldset id='3aUCa'></fieldset></dl></div>

                      <tfoot id='3aUCa'></tfoot>

                      <small id='3aUCa'></small><noframes id='3aUCa'>