簡體   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