Android-弹出菜单don';t显示在菜单操作栏下方
我创建了一个菜单和弹出菜单,如下图所示(我进入互联网,通过绘画编辑),我不知道为什么它不能正常显示。我想要这样的界面和moever,我如何改变弹出菜单的背景色?我试了如下,但没有成功。我在三星Galaxy J和安卓4.4.2上测试 MainActivity.javaAndroid-弹出菜单don';t显示在菜单操作栏下方,android,popupmenu,Android,Popupmenu,我创建了一个菜单和弹出菜单,如下图所示(我进入互联网,通过绘画编辑),我不知道为什么它不能正常显示。我想要这样的界面和moever,我如何改变弹出菜单的背景色?我试了如下,但没有成功。我在三星Galaxy J和安卓4.4.2上测试 MainActivity.java public class MainActivity extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanc
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);
}
}
activity_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>
menu_main.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>
styles.xml
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="android:background">#3079EB</item>
<item name="android:popupMenuStyle">@style/PopupMenu</item>
</style>
<style name="PopupMenu" parent="Widget.AppCompat.Light.PopupMenu">
<item name="android:popupBackground">@android:color/white</item>
</style>
#3079EB
@样式/弹出菜单
@android:彩色/白色
p/S:我是android开发的初学者,请将您的全部代码发布在这里。从第一眼看,我能理解的是,填充弹出菜单的布局高度非常高。因此,即使在填充了这四个项目之后,仍然有足够的空间。更改弹出窗口的布局高度,以包装内容,而不是使用固定高度。我希望这能解决这个问题。你能在这里发布你的全部代码吗。从第一眼看,我能理解的是,填充弹出菜单的布局高度非常高。因此,即使在填充了这四个项目之后,仍然有足够的空间。更改弹出窗口的布局高度,以包装内容,而不是使用固定高度。我希望这能解决问题。我更新了代码。我得到了这样的结果,但我想要这样。请一步一步地指导我,我对android不太了解:)我在哪里更改布局高度?为什么在menu_main.xml中使用同一个菜单两次?我只是复制了一个教程:D你有什么建议吗?我更新了代码。我得到了这样的结果,但我想要这样。请一步一步地引导我,我对android不太了解:)我在哪里更改布局?高度?为什么你在你的menu\u main.xml中使用同一个菜单两次?我只是复制了一个教程:D你有什么建议吗?你得到了上面的解决方案吗?我陷入了这个问题。如果你得到了正确的解决方案,那么请帮助我。你得到了上面的解决方案吗?我陷入了这个问题。如果你得到了答案正确的解决方案,那么请帮助我。