简体   繁体   English

Android studio - 更改 NOT OF BOTTOM NAVIGATION VIEW 的颜色

[英]Android studio - change color of NOT OF BOTTOM NAVIGATION VIEW

I want to change color of lower part in android studio And I am not talking about bottom navigation view I am talking about the three icons which are by default when open any app The icons are back button and home back and one square How can I change color of that我想在android studio中更改下部的颜色我不是在谈论底部导航视图我在谈论打开任何应用程序时默认的三个图标图标是后退按钮和主页后退和一个方块我如何更改那个颜色

Image is highlighting of what I want to change color of图像突出显示了我要更改颜色的内容

图像突出显示了我要更改颜色的内容

You cannot change those icons, they're device predefined icons for navigations.您无法更改这些图标,它们是设备预定义的导航图标。 You can how ever make it go away like below:你可以如何让它消失,如下所示:

findViewById(R.id.your_layout).setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);

Note that this might not work on latest android devices as I have only done this on older version of android like >4.4 Also, it's really not a good idea removing as it's device specific...you don't want to break your device!请注意,这可能不适用于最新的 android 设备,因为我只在旧版本的 android 上执行过此操作,例如 >4.4 此外,删除它真的不是一个好主意,因为它是特定于设备的......你不想破坏你的设备!

To change the color, you can try few methods below:要更改颜色,您可以尝试以下几种方法:

1 From the class 1从班级

if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        getWindow().setNavigationBarColor(getResources().getColor(R.color.white));
    }

2 as a style 2作为一种风格

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
    <item name="android:navigationBarColor">@color/white</item>
</style>

Update Due to the fact that you need to call getWindow() it will be impossible to run the code on Application class.更新由于您需要调用getWindow()因此无法在 Application 类上运行代码。

So, I will suggest a baseActivity instead...let it be known that, this suggestion is open for improvement.所以,我会建议一个 baseActivity 代替......让我们知道,这个建议是可以改进的。

There are multiple methods to get this done and they all have their down sides also.有多种方法可以完成这项工作,但它们也都有其缺点。

SUG ONE, create an open base class like below SUG ONE,创建一个如下所示的开放基类

open class BaseActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            window.navigationBarColor = resources.getColor(R.color.green)
        }
    }
}

So in your activities, you will have:因此,在您的活动中,您将拥有:

class LoginActivity : BaseActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_login)
    }
}

instead of:代替:

class LoginActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_login)
    }
}

Note: I have a feeling this is costly.注意:我觉得这很昂贵。

SUG TWO, since it's a single line of code, you can just run it across your activities, it basically have no optimizations effect or what so ever. SUG 2,因为它是一行代码,你可以在你的活动中运行它,它基本上没有优化效果或其他什么。

Note: programmers call it redundancy.注意:程序员称之为冗余。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何更改android studio底部导航栏上选择的图标颜色 - How to change the icon color selected on bottom navigation bar in android studio 如何在android studio中更改导航视图中汉堡包图标的颜色 - how to change the color of the hamburger icon in the navigation view in android studio Android底部导航查看项目文本颜色? - Android Bottom Navigation View item text color? 更改Android本机底部导航颜色? - Change Android native bottom navigation color? 创建底部导航视图后 Android Studio - After creating Bottom Navigation View Android Studio 如何在 Android Studio 中更改底部导航栏按钮的点击波纹效果颜色 - How to change on tap ripple-effect color of bottom-navigation-bar buttons in Android Studio Android Studio - onClick 片段事务不改变底部导航菜单图标颜色 - Android Studio - onClick Fragment Transaction does not change Bottom Navigation Menu Icon Color Kotlin android studio 底部导航栏选中项周围的颜色怎么改? - How to change the color that is around the selected item in android studio bottom navigation bar in Kotlin? 单击时如何不更改底部导航视图项目颜色 - How to not change Bottom Navigation View Item Color on click 如何更改底部导航视图顶部的线条颜色 - How to change color of the line that top of the bottom navigation view
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM