简体   繁体   English

我的actionBar没有出现

[英]My actionBar does not appear

I have been having trouble with my action bars, I got it set up on my xml front end like this: 我在操作栏时遇到了麻烦,我在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" />

And on the Java activity: 关于Java活动:

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

I have already tried changing the theme the app uses, the theme the layout uses and even the activities theme to allow/forbid a toolbar to show up. 我已经尝试过更改应用程序使用的主题,布局使用的主题,甚至是允许/禁止工具栏显示的活动主题。 Even though my java class extends AppCompatActivity it does not show! 即使我的Java类扩展了AppCompatActivity,它也不会显示!

PS: Got it working now! PS:现在可以正常工作了! The problem was the setup on java code itself, there was an hidden method which was overwritting my setup, thx for the help! 问题是Java代码本身的设置,有一个隐藏的方法覆盖了我的设置,请帮忙!

Make sure your activity inflates the correct layout containing your ToolBar. 确保您的活动夸大了包含工具栏的正确布局。

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

Your activity layout should contain your ToolBar. 您的活动布局应包含工具栏。 Here is a code example: 这是一个代码示例:

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