繁体   English   中英

我的actionBar没有出现

[英]My actionBar does not appear

我在操作栏时遇到了麻烦,我在xml前端设置了它,如下所示:

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar4"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/colorPrimary"
    android:label="@string/dadosCadastrais"
    android:minHeight="?attr/actionBarSize"
    android:theme="?attr/actionBarTheme" />

关于Java活动:

Toolbar toolbar = findViewById(R.id.toolbar4);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);

我已经尝试过更改应用程序使用的主题,布局使用的主题,甚至是允许/禁止工具栏显示的活动主题。 即使我的Java类扩展了AppCompatActivity,它也不会显示!

PS:现在可以正常工作了! 问题是Java代码本身的设置,有一个隐藏的方法覆盖了我的设置,请帮忙!

确保您的活动夸大了包含工具栏的正确布局。

protected void setContentView() {
    setContentView(R.layout.your_activity_layout);
}

您的活动布局应包含工具栏。 这是一个代码示例:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:keepScreenOn="true"
    android:orientation="vertical">

    <android.support.v7.widget.Toolbar
        android:id="@id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar" />

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/frameLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"></FrameLayout>

</LinearLayout>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM