【问题标题】:Should we use NoActionBar theme or not?我们是否应该使用 NoActionBar 主题?
【发布时间】:2021-04-30 03:47:25
【问题描述】:

我正在使用 NavigationGraph 和其他 Jetpack 库创建一个只有 一个 Activity 和多个片段的 android 应用程序。我的问题是,根据为应用程序提供的设计,它在不同的屏幕上有不同类型的工具栏(有些有多行文本,有些在工具栏中有适当的按钮(不是工具栏菜单),还有一些搜索工具栏)。

从某种意义上说,您可以在不同的屏幕上使用多种类型的工具栏。

那么,我应该遵循什么方法:

  1. 只需自定义与默认工具栏不同的工具栏

注意:我很难使用这种方法,因为我无法自定义工具栏,因为 (activity as AppCompatActivity).setSupportActionBar(binding.customToolbar) 行没有任何效果

  1. 在应用中使用 NoActionBar 主题并在所有屏幕中手动添加工具栏

我没有尝试过这种方法,只是想在开始之前了解一下

【问题讨论】:

    标签: android android-layout kotlin android-fragments


    【解决方案1】:

    根据Support app bar variations guide,建议使用NoActionBar 主题并让每个屏幕都有自己的Toolbar。在这种情况下,您根本不会使用setSupportActionBar()(相反,如果您想使用菜单项等,请使用toolbar APIs directly

    【讨论】:

      【解决方案2】:
          You just  remove the toolbar and add your custom toolbar it having two methods 
          1.add theme in `mainfest` file like this
           <style name="`AppTheme.NoActionBar`">
                  <item name="windowActionBar">false</item>
                  <item name="windowNoTitle">true</item>
              </style>
          Add this line in your manifest likethis
          android:theme="@style/Theme.Product"
          2. Method is add this line in your activity
            getSupportActionBar().hide();
      Thank you
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-05-22
        • 2021-10-19
        • 2014-10-07
        • 2016-07-31
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多