Android - 弹出菜单不会显示在菜单操作栏下方

时间:2015-09-15 09:30:12

标签: android popupmenu

我创建了一个菜单和弹出菜单,如下图所示(我上网并通过绘画进行编辑),我不知道它为什么显示正常http://i.imgur.com/jHPobCH.png。我想要这样的界面http://i.imgur.com/08XomVV.png和moever,如何更改弹出菜单背景颜色?我尝试如下,但没有成功。我测试三星Galaxy J和android 4.4.2。

MainActivity.java

<?xml version="1.0"?>
<configuration>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>

  <system.web>
    <webServices>
      <soapExtensionTypes>
        <add type="MyServiceClient.MySeriviceSoap, MyServiceClient, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" priority="1" />
      </soapExtensionTypes>
    </webServices>
  </system.web>
</configuration>

activity_main.xml中

public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

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

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

menu_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:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">


    <WebView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/webView"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />
</RelativeLayout>

styles.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity">
    <item android:id="@+id/action_filter"
        android:icon="@drawable/ic_filter_white_18dp"
        android:title="@string/action_filter"
        app:showAsAction="ifRoom" />
    <item android:id="@+id/action_label"
        android:icon="@drawable/ic_add_circle_outline_white_18dp"
        android:title="@string/action_label"
        app:showAsAction="ifRoom" />
    <item android:id="@+id/action_settings"
        android:title="@string/action_settings"
        app:showAsAction="never" />
</menu>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity">
    <item android:id="@+id/action_filter"
        android:icon="@drawable/ic_filter_white_18dp"
        android:title="@string/action_filter"
        app:showAsAction="ifRoom" />
    <item android:id="@+id/action_label"
        android:icon="@drawable/ic_add_circle_outline_white_18dp"
        android:title="@string/action_label"
        app:showAsAction="ifRoom" />
    <item android:id="@+id/action_settings"
        android:title="@string/action_settings"
        app:showAsAction="never" />
</menu>

P / S:我是一个初学的android开发者

1 个答案:

答案 0 :(得分:0)

您能在这里发布您的全部代码吗?从第一眼看,我可以理解的是,布局弹出菜单的布局高度非常高。因此,即使填充了四个项目,它也有足够的空白空间。将要弹出弹出窗口的布局的layout_height更改为wrap-content而不是使用某个固定高度。我希望这能解决问题。