【问题标题】:Making YesActionBar and NoActionBar theme in Android and using them in application在 Android 中制作 YesActionBar 和 NoActionBar 主题并在应用程序中使用它们
【发布时间】:2015-06-17 13:59:26
【问题描述】:

我想在我的 android 应用程序中创建简单的活动,并将它们分为 no-action bar 和 action-bar 活动。为了实现这个目标,我在styles.xml文件中创建了2个样式:

<style name="AppTheme" parent="Theme.AppCompat.Light">
</style>

<style name="NoActionBar" parent="Theme.AppCompat.NoActionBar">
</style>

此外,我的 android 清单包含以下代码行:

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

因为我想默认使用 AppTheme。如何在我的活动中使用NoActionBar 样式?

我尝试将其用作:style="@style/NoActionBar" 和 android:theme="@style/NoActionBar",但没有任何成功。

我想通过编辑 .xml 文件来覆盖默认样式。你能帮我解决这个问题吗?

我目前的 API 级别是 11

【问题讨论】:

  • @DerGolem 我已经尝试过这样做,但没有任何成功 - 操作栏仍然可见。我还能做些什么来改变它(比如提高 API 级别)?
  • @DerGolem 谢谢! :)
  • 我把我的评论变成了答案,这样你就可以接受它并将这篇文章从未回答的问题队列中删除。

标签: java android android-activity android-actionbar


【解决方案1】:

您可以在代码中删除 ActionBar,方法是在“无操作”Activity/es 的 onCreate() 事件中将其设置为不可见(嗯,它真的消失了)。
或者在您的“无动作”片段的onCreateView() 事件中。

ActionBar actionBar = getActionBar();
actionBar.hide();

来源:http://developer.android.com/guide/topics/ui/actionbar.html#Removing

【讨论】:

    【解决方案2】:

    您可以将样式放在应用程序标记中,该标记将应用于应用程序中的所有活动。然后,要指定哪些活动使用特定主题,您可以在每个活动标记后添加同一行代码。

    或者,在你的类(代码不是 xml)中,你可以指定:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        //Default method calls
        setTheme(R.style.AppTheme);
        super.onCreate(savedInstanceState);
    

    我还建议将其用作父主题:@android:style/Theme.Holo.Light.NoActionBar

    【讨论】:

    • 你不能使用Theme.Holo.Light.NoActionBar和appcompat的东西
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-01
    • 1970-01-01
    • 2022-01-05
    • 1970-01-01
    相关资源
    最近更新 更多