【问题标题】:Android ActionBar Overlap with Settings OptionsAndroid ActionBar 与设置选项重叠
【发布时间】:2015-05-14 21:55:34
【问题描述】:

从下图中可以看出,我的操作栏菜单项与我的自定义操作栏重叠。这是因为我使用了主题 .NoActionBar 然后在 .java 中声明我自己的操作栏如下:

public class MenuActivity extends ActionBarActivity {

private Toolbar toolbar;

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

    toolbar = (Toolbar) findViewById(R.id.tool_bar);
    setSupportActionBar(toolbar);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu, menu);
    return super.onCreateOptionsMenu(menu);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    int id = item.getItemId();

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

    return super.onOptionsItemSelected(item);
}

工具栏:

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:theme="@style/ThemeOverlay.AppCompat.Dark"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/ColorPrimary"
android:elevation="4dp">

还有布局...

<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"

tools:context=".MainActivity">

<include
    android:id="@+id/tool_bar"
    layout="@layout/custom_toolbar"
    ></include>

<TextView
    android:layout_below="@+id/tool_bar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world" />

如您所见,问题出在 .NoActionBar 主题。我试过环顾四周并在我的菜单项顶部添加一个填充,但是它不起作用。任何帮助表示赞赏。

【问题讨论】:

    标签: android android-actionbar


    【解决方案1】:

    这是完全可以预料的行为,并遵循Material Design 官方指南。

    菜单出现在所有其他应用内 UI 元素之上。

    它是由Theme.Material 主题(如果您使用 API > 21)或Theme.AppCompat(如果您使用的是support-v7)提供给您的。你不应该担心这个。

    如果这不是您对应用程序的期望,请尝试切换到较旧的主题,例如 Holo 的东西。从设计的角度来看,这并不是真正推荐的。

    【讨论】:

    • 干杯对不起我只是更新自己啊哈
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-11
    • 1970-01-01
    • 2023-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多