I am new to android development and was developing an overflow menu. I had to change the theme of my project to holo.light to make the action bar visible, but when I try to do so following error occurs ;
After a lot of searching on the internet I realised that only the themes that begin with AppCompat.something.something were working properly. All the rest were not rendered.
Please help.
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.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>
androidmanifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.naveenjain.test7">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
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>
</manifest>
You are getting this error because android studio is not able to render correct theme for this layout.
This is android studio problem. if you run this application it will run successfully. to solve this problem
Select Design tab in android studio when you open layout.
2.Select Theme option from tool bar area in android studio.
A window will appear choose project theme.
Your all project theme appear in right side section.
Select appropriate theme.
these steps will solve this error.
Related
I am a beginner of android,Kotlin,
I don't know how to remove the top app bar in a specific and all activities.
I have a splash screen and a new activity
Below is my style's code,I already imported a material design in styles.xml
I don't know what is the way to remove the top app bar in styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
</resources>
Android Manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.shanjostech.newsample">
<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=".Main_Screen"></activity>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Add theme attribute to the activity where you want to hide appbar in manifest file
<activity
android:name="com.mvvm.Activity"
android:label="#string/app_name"
android:theme="#style/NewTheme">
</activity>
then create a new theme in style.xml with parent as Theme.AppCompat.NoActionBar
<style name="NewTheme" parent="Theme.AppCompat.NoActionBar">
</style>
This question is already answered here:-
How to remove it from all activities
How to remove it from specific activity
In Case if none of them work fine for you then try this:-
For specific activity,
Set theme in manifest file as mentioned below:-
<activity android:name=".activity.ContinueLoginActivity"
android:theme="#style/Theme.AppCompat.Light.NoActionBar"
android:screenOrientation="portrait" />
Programmatically :-
Kotlin:
supportActionBar?.hide()
Java:
if (getSupportActionBar() != null) {
getSupportActionBar().hide();
}
for remove it from all activities change .DarkActionBar by .NoActionBar in style.xml file:-
<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>
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.
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
i define two theme in styles.xml
AppTheme1 and AppTheme2:
<resources>
<!-- Base application theme. -->
<style name="AppTheme1" 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="AppTheme2" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#00ff00</item>
<item name="colorPrimaryDark">#ff00ff</item>
<item name="colorAccent">#0000ff</item>
</style>
</resources>
when i change theme in application tag inside AndroidManifest.xml
my app theme doesn't any change and the app only use colors.xml and not styles.xml.
for example my manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.maneshtsoft.blackdictionary">
<application
android:allowBackup="true"
android:icon="#mipmap/favicondark"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme2">
<!-- OR AppTheme1 does not matter -->
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
just say that i use toolbar and AppCompactActivity maybe help to answer.
thanks.
The problem may be the cache of InstantRun.
Did you try "Clean & Rerun"? If you use AndroidStudio 2.1 or higher, Select Menu -> Run -> Clean & Rerun.
In my application I have a lot of layers and instead of setting a background image to each of them, I want to set a background once and for all. How can I do that?
Take a look at Apply a theme to an Activity or application to apply the background image across the whole application.
Add android:windowBackground to your theme:
<!-- 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>
<item name="android:windowBackground">#color/colorPrimaryDark</item>
</style>
And of course make sure your manifest uses the theme for you application:
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.package.name"
xmlns:android="http://schemas.android.com/apk/res/android">
<application
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>
</manifest>