Vaibhav Kumar
Vaibhav Kumar

Reputation: 159

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

Image is highlighting of what I want to change color of

Image is highlighting of what I want to change color of

Upvotes: 2

Views: 134

Answers (1)

Wale
Wale

Reputation: 1806

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!

To change the color, you can try few methods below:

1 From the class

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

2 as a style

<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.

So, I will suggest a baseActivity instead...let it be known that, this suggestion is open for improvement.

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

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.

Note: programmers call it redundancy.

Upvotes: 2

Related Questions