gpt4 book ai didi

android - getActionBar() 总是返回 null

转载 作者:行者123 更新时间:2023-11-29 15:10:50 27 4
gpt4 key购买 nike

我在 Stackoverflow 中浏览过很多类似的帖子,但似乎没有任何方法可以解决我的问题。

我正在尝试获取 ActionBar 并调用 setDisplayHomeAsUpEnabled(true)

我可以看到黑色的 ActionBar(因为主题是黑色背景), Activity 名称显示为标题。但是在我的 Activity 代码中,如果我尝试执行 getActionBar(),它总是返回 null。

我尝试了 onResume()onCreate() 中的代码(在展开布局之后)。它到处都返回空值。有什么我想念的吗?

AndroidManifest.xml

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".ActivityMain"
android:label="@string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

这是我的样式定义。我正在使用 Theme.AppCompat.Light.DarkActionBar 主题

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>

此外,我正在使用以下依赖项:

    compile 'com.android.support:support-v4:22.1.0'
compile 'com.android.support:appcompat-v7:22.2.0'

我的 Activity 类定义是:

MainActivity extends AppCompatActivity

最佳答案

尝试使用 getSupportActionBar()。最新的 appcompat-v7 似乎禁用了系统栏。

关于android - getActionBar() 总是返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31888776/

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