Android中的空菜单窗口
在我的应用程序中,actionbar中的菜单没有正确呈现。它全是白色,大小不正常。我试图改变背景,我可以看到文字,但形状仍然不正常 菜单正在运行,您可以单击并 使用布局检查器拍摄吹扫照片 我已经搜索了几乎所有的东西来获得正常的菜单,但是找不到一个方法Android中的空菜单窗口,android,android-layout,menu,Android,Android Layout,Menu,在我的应用程序中,actionbar中的菜单没有正确呈现。它全是白色,大小不正常。我试图改变背景,我可以看到文字,但形状仍然不正常 菜单正在运行,您可以单击并 使用布局检查器拍摄吹扫照片 我已经搜索了几乎所有的东西来获得正常的菜单,但是找不到一个方法 布局似乎没有正确充气 文本颜色与背景相同 有什么建议吗 赛特尔 菜单创建 public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = get
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_main, menu);
return true;
}
论创造
protected void onCreate(Bundle savedInstanceState) {
setTheme(R.style.AppTheme);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_test);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
toolbar.setTitle(R.string.MainTitle);
CollapsingToolbarLayout mCollapsingToolbarLayout = findViewById(R.id.collapsing_toolbar);
与AppBarLayout相关的XML部分
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:expandedTitleTextAppearance="@style/ExpandedAppBar"
app:collapsedTitleTextAppearance="@style/CollapsedAppBar"
app:expandedTitleGravity="bottom|center_horizontal"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:toolbarId="@+id/toolbar">
<ImageView
android:id="@+id/imageview_topMainActivity"
android:layout_width="match_parent"
android:layout_height="200dp"
android:scaleType="fitXY"
android:src="@drawable/header"
app:layout_collapseMode="parallax"
/>
<include layout="@layout/toolbar"/>
工具栏中的XML
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin">
</androidx.appcompat.widget.Toolbar>
我运行了你的代码,也遇到了类似的问题。然后我从androidx软件包中将AppBarLayout中的“android:theme”更改为一个新的,菜单中的文本变得可见:
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:theme="@style/ThemeOverlay.MaterialComponents.ActionBar.Primary"
>
这就是你要找的吗
关于大小,它是androidX新样式的默认值。但如果你想让它像以前一样,那么你需要改变父母
“parent=“Theme.MaterialComponents.Light.NoActionBar”
到
“parent=”Theme.MaterialComponents.Light.NoActionBar.Bridge”
在你的AppTheme风格下。我运行了你的代码,也遇到了类似的问题。然后我从androidx软件包中将AppBarLayout中的“android:theme”更改为一个新的,菜单中的文本变得可见:
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:theme="@style/ThemeOverlay.MaterialComponents.ActionBar.Primary"
>
这就是你要找的吗
关于大小,它是androidX新样式的默认值。但如果你想让它像以前一样,那么你需要改变父母
“parent=“Theme.MaterialComponents.Light.NoActionBar”
到
“parent=”Theme.MaterialComponents.Light.NoActionBar.Bridge”
在你的AppTheme风格中。你能提供一个如何初始化actionBar的代码吗?我认为,这两种方法都有帮助。首先,我想了解,你是否使用工具栏,我想看看你如何在活动(或片段)中初始化菜单。如果你也提供样式ExpandedAppBar和CollapsedAppBar会更好。ExpandedAppBar CollapsedAppBar除了
parent=“@android:style/TextAppearance.Medium”之外没有其他特殊样式
您能提供一个如何初始化actionBar的代码吗?我认为,这两种方法都有帮助。首先,我想了解,你是否使用工具栏,我想看看你如何在活动(或片段)中初始化菜单。如果你也提供样式ExpandedAppBar和CollapsedAppBar会更好。ExpandedAppBar CollapsedAppBar除了parent=“@android:style/TextAppearance.Medium”之外没有其他特殊样式
首先,我建议您将AppTheme设置为手动设置的工具栏。老实说,正如您所见,我没有过大的菜单。可能,这与操作系统版本有关。我正在安卓9模拟器上启动它。你有哪一个?那些截图我看不清楚。在第一个工具栏上,你有一个超大的工具栏,但是在从layout inspector获取的屏幕截图上,它们比第一个工具栏上的要小一些。因此,我有一个假设:属性showAsAction
工作不正常,菜单充气器试图将其安装到下拉列表中,而不是将其放置在菜单按钮的左侧。或者您是否在抱怨androidX样式的工具栏使其比旧的工具栏更大?我想,是的。似乎他们增加了更多的圆角,使其更大。首先,我建议您将AppTheme设置为手动设置工具栏。老实说,正如您所见,我没有超大的菜单。可能,这与操作系统版本有关。我正在安卓9模拟器上启动它。你有哪一个?那些截图我看不清楚。在第一个工具栏上,你有一个超大的工具栏,但是在从layout inspector获取的屏幕截图上,它们比第一个工具栏上的要小一些。因此,我有一个假设:属性showAsAction
工作不正常,菜单充气器试图将其安装到下拉列表中,而不是将其放置在菜单按钮的左侧。或者您是否在抱怨androidX样式的工具栏使其比旧的工具栏更大?我想,是的。似乎他们增加了更多的圆角,使其更大。
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin">
</androidx.appcompat.widget.Toolbar>
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:theme="@style/ThemeOverlay.MaterialComponents.ActionBar.Primary"
>