gpt4 book ai didi

java - 我的操作栏没有出现

转载 作者:行者123 更新时间:2023-12-02 11:45:34 25 4
gpt4 key购买 nike

我的操作栏遇到了问题,我在 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 Activity :

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

我已经尝试更改应用程序使用的主题、布局使用的主题甚至 Activity 主题以允许/禁止工具栏显示。即使我的 java 类扩展了 AppCompatActivity,它也没有显示!

PS:现在可以使用了!问题是java代码本身的设置,有一个隐藏的方法覆盖了我的设置,感谢帮助!

最佳答案

确保您的 Activity 扩展了包含工具栏的正确布局。

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

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

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

关于java - 我的操作栏没有出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48230375/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com