标签: android-navigation-bar

如何在Bottombar上方显示Snackbar?

我正在使用roughike的BottomBar 2.0:https : //github.com/roughike/BottomBar/

当我显示 SnackBar 时,它会显示在 BottomBar 本身上。

我希望它被绘制在 BottomBar 上方。

活动_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/main_activity"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/here"
        android:background="#fff">

        <FrameLayout
            android:id="@+id/contentContainer"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_above="@+id/bottomBar">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text="Three Buttons Bar"
                android:id="@+id/textView"
                android:layout_centerVertical="true"
                android:layout_centerHorizontal="true"
                android:textColor="@color/colorPrimary"
                android:textSize="35sp" />

        </FrameLayout>

        <com.roughike.bottombar.BottomBar
            android:id="@+id/bottomBar"
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:layout_alignParentBottom="true"
            app:bb_tabXmlResource="@xml/bottombar_tabs" />
    </RelativeLayout>

</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

主活动.java:

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        BottomBar bottomBar = (BottomBar) findViewById(R.id.bottomBar);
        bottomBar.setOnTabSelectListener(new OnTabSelectListener() …
Run Code Online (Sandbox Code Playgroud)

android material-design android-snackbar android-navigation-bar

5
推荐指数
3
解决办法
9748
查看次数

在应用启动时立即隐藏状态栏和导航栏

我想知道是否有办法在应用程序启动时隐藏 Android 设备的软键(状态和导航栏)?以一个游戏为例,它最初显示黑屏,同时在运行时隐藏品牌、标题和主菜单屏幕之前的软键。

我在我的 MainActivity 中包含了以下代码片段,当应用程序启动时,我最初在运行时看到一个带有软键的白屏大约一秒钟,然后当 MainActivity 的线程完成运行时软键消失:

@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    if (hasFocus) {
        getWindow().getDecorView().setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                        | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                        | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_FULLSCREEN
                        | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
    }
}
Run Code Online (Sandbox Code Playgroud)

谢谢一堆。

* 2017 年 1 月 19 日更新:* 包括:

<item name="android:windowFullscreen">true</item>
Run Code Online (Sandbox Code Playgroud)

...进入应用程序的主题,只有状态栏按时隐藏,而不是导航栏。我的第二篇文章 -在应用启动时立即隐藏导航栏

android runtime launch android-statusbar android-navigation-bar

5
推荐指数
1
解决办法
8154
查看次数

Android - 为带有导航抽屉和应用栏的应用完全隐藏状态和导航栏

如何动态隐藏状态和导航栏彻底

该应用程序包含一个带有应用栏/工具栏和 FAB 按钮的常规导航抽屉。

当切换到全屏模式,在内容的导航和状态栏的滚动了。屏幕上留下两个空条。我想要隐藏那些空条。

我创建了一个最小的演示应用程序。左侧是常规应用程序。当推动晶圆厂时,应用程序应该全屏显示。

在此处输入图片说明

我怎样才能让酒吧隐藏?

问题:请写出最小演示项目中需要哪些更改?

更新了第二个解决方案

@Roaim 提供的 GREAT 解决方案有效。必要的是将android:fitsSystemWindows布局属性设置为 false。

如果您仍然无法显示和隐藏状态/导航栏,此解决方案可能会对您有所帮助。

完全隐藏条形:

public static void hideSystemUI() {
    if (getSupportActionBar() != null) {
        getSupportActionBar().hide();
    }
    getWindow().getDecorView().setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_IMMERSIVE
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_FULLSCREEN);
}
Run Code Online (Sandbox Code Playgroud)

并显示所有条:

public static void showSystemUI() {
    if (getSupportActionBar() != null) {
        getSupportActionBar().show();
    }
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
}
Run Code Online (Sandbox Code Playgroud)

android-layout android-actionbar android-fullscreen android-statusbar android-navigation-bar

5
推荐指数
1
解决办法
4783
查看次数

Material Design 3 使用 colorPrimary 作为 actionBar、navBar 和日历背景颜色。我如何禁用此功能?

升级到 Material Design 3 后,我注意到某些东西的背景颜色变成了我的原色设置的褪色版本。例如,如果我将主颜色设置为红色,则导航栏和日历现在有点粉红色。

<style name="AppTheme" parent="Base.AppTheme" />

<style name="Base.AppTheme" parent="Theme.Material3.DayNight.NoActionBar">
    <item name="colorPrimary">@color/red</item>

</style>
Run Code Online (Sandbox Code Playgroud)

我不知道为什么材料设计假设我想要这些背景颜色。我的设计文档需要白色背景,并且无法将主色设置为白色。如果我根本不设置原色,它默认为紫色!

我对导航栏有一些运气,因为你可以设置每个项目的背景颜色,但对日历则没有运气。我尝试过在日历样式上设置所有听起来与颜色相关的内容。到目前为止,除了primaryColor 之外,日历背景没有任何改变。backgroundColor、backgroundTint 等。没有任何效果。有谁知道如何在 Material Design 3 上覆盖这种行为?

我只想将 colorPrimary 设置为绿色,并将 actionBar、navBar 和 calendar 的背景颜色设置为白色。

android android-calendar material-design android-navigationview android-navigation-bar

5
推荐指数
1
解决办法
3066
查看次数

将我的工具栏图像显示为状态栏的背景,从而影响 android 中的导航栏

我希望我的工具栏占据状态栏的空间,并将用于它的图像作为状态栏的背景,我在我的活动中使用此代码成功地做到了这一点

    //    for using status bar space
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
                WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
    }
Run Code Online (Sandbox Code Playgroud)

问题是这段代码使我的活动布局即使是带有导航栏的空间也全屏显示,那么如何解决这个问题?

这是屏幕图像 在此处输入图片说明

android android-layout android-toolbar android-statusbar android-navigation-bar

4
推荐指数
1
解决办法
1726
查看次数

Android:windowLightNavigationBar 不起作用

背景:我的背景是 Web 开发、ruby 和 javascript。我正在开发一个主要是 react-native 的应用程序,所以很可能我错过了一些基本的东西。

我想要的是

android 导航栏为白色,带有深色系统按钮,请参阅链接白色导航栏中的图像

我当前的代码

res/values/style.xml

<resources>
  <style name="AppTheme" parent="Theme.AppCompat.Light">
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:windowLightNavigationBar">true</item> 
    <item name="android:windowTranslucentNavigation">false</item>
    <item name="android:navigationBarColor">#FFFFFF</item>
  </style>
</resources>
Run Code Online (Sandbox Code Playgroud)

正在发生的事情

背景和按钮是白色的。这对 UX 来说不是很好。

** 我尝试过的 **

这就是我现在所处的位置在 Android 上更改导航栏图标颜色

我试过将 style.xml 放在一个values-v27文件夹中。

android android-navigation-bar

2
推荐指数
1
解决办法
4114
查看次数

SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR 不适用于 API 28

我有一个问题,SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR不知何故无法工作,但SYSTEM_UI_FLAG_LIGHT_STATUS_BAR正在工作。我目前正在使用 Android API 28。

那么发生了什么?在 API 23 及以下版本上,我按预期获得半透明状态栏和导航栏。在 API 23 和 API API 26 之间,我按预期获得了半透明的导航栏和灯光模式状态栏。但是在 API 27 及更高版本上,我获得了 Light Mode Status Bar 而不是 Light Mode Navigation Bar。它只是普通的黑色,没有任何变化。

这是我的 MainActivity 和我的代码,用于根据 Android API 级别启用半透明或浅色模式状态栏和导航栏(注意我的评论描述了哪些有效,哪些无效):

View decorView = getWindow().getDecorView();
Window win = getWindow();

//Setup Status Bar and Nav Bar white if supported
if(Build.VERSION.SDK_INT >= 27) {
    decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);// <- works not
    decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); // <- works
}
else if (Build.VERSION.SDK_INT >= 23 && Build.VERSION.SDK_INT < 27) {
    //this here works …
Run Code Online (Sandbox Code Playgroud)

android android-theme android-styles android-navigation-bar

2
推荐指数
1
解决办法
3996
查看次数

在新手机中 React Native 应用程序“全屏”

我的目标是使应用程序全屏显示状态栏在 Android 和 iPhone 中可见,就像在 Expo 中一样,但在 React Native 中

这是正在发生的事情:

我的目标是移除这个灰色部分,让应用占据这部分,同时显示状态栏,就像在 Expo 中一样。

我已经试过了:https : //reactnative.dev/docs/statusbar.html#sethidden

但是所有的灰色顶部都变成黑色并且没有状态栏

我已经尝试将其添加到 Android 中的 styles.xml 中:

<item name="android:windowFullscreen">true</item>
Run Code Online (Sandbox Code Playgroud)

但什么都没有改变(并且只能在 Android 中使用)

statusbar react-native android-navigation-bar iphone-x android-9.0-pie

2
推荐指数
1
解决办法
2745
查看次数

错误:无法转换为 androidx.navigation.fragment.NavHostFragment。-- 应用程序每次都会崩溃

因此,我正在尝试构建一个带有底部导航栏的应用程序,该导航栏将在片段之间切换。我根据一些文档进行了编码。

我尝试了互联网上的所有解决方案,但似乎没有一个适合我。

错误:

Caused by: java.lang.ClassCastException: com.example.jetpacklesson.MainFragment cannot be cast to androidx.navigation.fragment.NavHostFragment
        at com.example.jetpacklesson.MainActivity.onCreate(MainActivity.java:30)
Run Code Online (Sandbox Code Playgroud)

这是 XML 主要活动代码

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <androidx.fragment.app.FragmentContainerView
        android:id="@+id/firstFragmentHolder"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:name="com.example.jetpacklesson.MainFragment"
        app:defaultNavHost = "true"
        app:layout_constraintBottom_toTopOf="@+id/bnv_bottomBar"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:navGraph = "@navigation/nav_graph"/>

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bnv_bottomBar"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:menu="@menu/nav_bottom_navigation" />
</androidx.constraintlayout.widget.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

和主要活动java代码:


    BottomNavigationView bnv_navigationBar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        NavHostFragment navHostFragment = (NavHostFragment) getSupportFragmentManager().findFragmentById(R.id.firstFragmentHolder);
        NavController navController = navHostFragment.getNavController();
        bnv_navigationBar = findViewById(R.id.bnv_bottomBar);
        NavigationUI.setupWithNavController(bnv_navigationBar, navController);
    }
Run Code Online (Sandbox Code Playgroud)

java android android-fragments android-studio android-navigation-bar

2
推荐指数
1
解决办法
1447
查看次数

如图所示,底部栏的名称是什么?

请在以下链接中提供图片。这个带有图标的栏的术语或官方术语是什么?

android view android-navigation-bar

1
推荐指数
1
解决办法
6996
查看次数

Android:如何设置状态栏和导航栏半透明

在某些应用程序中,我注意到状态栏和导航栏是透明的,但并非完全.我不知道这是背景颜色还是别的.有人会告诉我如何实现这个吗?谢谢.

在此输入图像描述

android android-layout android-xml android-statusbar android-navigation-bar

0
推荐指数
2
解决办法
5283
查看次数