BottomNavigationView not accepting styles - android

Can someone please help me understand how to add a background color to my bottom navigation view. I have tried a multitude of things online. If I specify individual colors for each of background, itemBackground, itemIconTint etc. then it shows in the AS preview but doesn't reflect on the device when I launch the app. [The device has Android 8.0.0 on it].
If I use the style attribute then the BottomNavigationView vanishes from the AS preview and there is no difference in the application when I run it. I was successfully able to apply ripple effects to the icon clicks but this seems to completely stump me. And as per Android styles this should have worked. [https://developer.android.com/guide/topics/ui/look-and-feel/themes#Theme]
Code in styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBars">
<item name="windowActionBar">true</item>
<item name="windowNoTitle">true</item>
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name="BottomNavigation" parent="AppTheme">
<item name="android:background">#color/colorAccent</item>
<item name="itemBackground">#drawable/bottom_navigation_colors</item>
<item name="itemIconTint">#drawable/navigation_bar_txt_color</item>
<item name="itemTextColor">#drawable/navigation_bar_txt_color</item>
</style>
</resources>
My Manifest has the following
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".screens.MainActivity"
android:label="#string/title_activity_main"
android:theme="#style/AppTheme.NoActionBars">
<!--<intent-filter>-->
<!--<action android:name="android.intent.action.MAIN" />-->
<!--<category android:name="android.intent.category.LAUNCHER" />-->
<!--</intent-filter>-->
</activity>
<activity android:name=".screens.LoginActivity"
android:label="LoginActivity"
android:theme="#style/AppTheme.NoActionBars">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

I tried using navigation.setBackgroundColor() from the Java code and it worked for me.
But I still cannot get it to work using XML and styles. So will mark this as the answer for now, until a better answer explains why XML style isn't working.

Related

Unable to remove Action Bar in Android tabLayout

I'm trying to get rid of the ActionBar in an android app.
here's the manifest
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
and here's the styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"/>
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"/>
</resources>
I did change the AppTheme style to NoActionBar, but the emulator still shows the action bar, What am I missing ?
it's because you are setting wrong theme for your app,AppTheme parent should remove action bar
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="AppThemeNoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="AppThemeNoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
</resources>
Remove android:theme="#style/AppTheme.NoActionBar from MainActivity entry in the manifest and then run your app.
stupidly enough, I didn't take a look at the main activity xml, which included an AppBarLayout widget, so I removed it and rearranged the layout, and now no action bar appears

Setting the ActionBar background colour to other than colorPrimary in XML

I have found similar questions but the answers did not work. I do not want to change the colorPrimary.
The ActionBar is not a ToolBar, so it does not exist in the activity's layout XML. The following did not work, and the bakground was still set to colorPrimary.
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat">
<!-- Customize your theme here. -->
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:statusBarColor">#color/colorBlack</item>
<item name="android:colorBackground">#color/colorBlack</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:backgroundStacked">#color/colorBlack</item>
<item name="android:backgroundSplit">#color/colorBlack</item>
<item name="android:background">#color/colorBlack</item>
</style>
</resources>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
Programmatically you can do
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#YOUR_COLOR")));

Set ToolBar label in Manifest or activity.xml

I keep seeing my domain name in the ToolBar in the past I would just use the Manifest file with this line android:label="#string/app_name" I can accomplish this in the ActivityMain.java with title. but would prefer to use the xml and strings concept. The only thing I have done different is create a custom style in the styles.xml for some TextView widgets tools v 24.0.2 V7 24.2.0 code posted
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<!--<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Light"/>
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"/>-->
<style name="MyStyle" parent="AppTheme">
<item name="android:textColor">#f10909</item>
<item name="android:textSize">20sp</item>
<item name="android:width">190dp</item>
</style>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.XXX.newstyletest">
<application>
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:title="what the Hell"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity" android:theme="#style/MyStyle">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
Is this an issue because of the custom style of has something changed ?
or what the heck am I doing wrong
You're going to scream when you SEE what is wrong if you look real close at you AndroidManifest.xml file you will see you have a situation where the code below the is UNREACHABLE because you have a closing brace behind the word application So just remove that > and life will be good

Android Material Design- ActionBar and Title visible even after setting windowActionBar as false and windowNoTitle as true

I am trying out the material design. I created a theme MyMaterialTheme in the styles.
Styles:
<resources>
<!-- Theme for the material design of the app -->
<style name="MyMaterialTheme" parent="MyMaterialTheme.Base"></style>
<style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="colorPrimary">#color/colorPrimaryApp</item>
<item name="colorPrimaryDark">#color/colorPrimaryDarkApp</item>
<item name="colorAccent">#color/colorAccentApp</item>
</style>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>
In my AndroidManifest.xml, I included this theme (MyMaterialTheme). I can confirm that my theme is applied as it has taken the correct colors from it. I had assigned windowActionBar as false and windowNoTitle as true, but still I am seeing the ActionBar and the title when I run the app. Could anyone point out where I am going wrong?
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/MyMaterialTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name">
<!-- android:theme="#style/AppTheme.NoActionBar"> -->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Here is the screenshot of the emulator:
Check your activity_main.xml file. Android Studio's default layouts will typically have a toolbar manually added to each layout, even if your app theme says there is none.
your base style that your material style extend it should be noTitlebar like this code
parent="Theme.AppCompat.Light.NoActionBar"

Android. My custom theme is not applied

I have following style definitions in my res/values/style.xml file:
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:textColor">#fff</item>
<item name="android:textSize">12sp</item>
</style>
<style name="MainActivity" parent="AppTheme">
<item name="android:textColor">#f0f</item>
<item name="android:background">#color/black</item>
</style>
And following code in manifest file:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:theme="#style/MainActivity"
android:name="com.example.mygateway.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
I expect that textColor #f0f will be applied to MainActivity activity, but it isn't.
Neither textColor no other items i tried are applied.
Actually the only AppTheme is applied to the activity and the whole application.
I'am a beginner in android development. What I do wrong?
Please help.
Thanks!
As official docs state:
"If you want to inherit from styles that you've defined yourself, you do not have to use the parent attribute. Instead, just prefix the name of the style you want to inherit to the name of your new style, separated by a period. For example, to create a new style that inherits the CodeFont style defined above, but make the color red, you can author the new style like this:"
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:textColor">#fff</item>
<item name="android:textSize">12sp</item>
</style>
<style name="AppTheme.MainActivity">
<item name="android:textColor">#f0f</item>
<item name="android:background">#color/black</item>
</style>
and
<activity android:theme="#style/AppTheme.MainActivity"
...>
...
</activity>`

Categories

Resources