App Crash at Launch (Material Theme issue) - android

I'm actually creating an app an I would like to use Material Theme Light.
So I put the line android:theme = "#android:style/Theme.Material.light"
on the manifest and no errors are displayed.
However when launching the app on my phone it crashes at launch although no errors are displayed in my xml/java sources.
I'm sure this line is the cause, because when I change the manifest to #style/AppTheme, it works and lauches.
It's driving me crazy, I need your help please.

It depends on your activity, What does your activity extend from? If it extends from AppCompatActivity you can't set material theme.
you should set AppTheme as your theme android:theme="#style/AppTheme"
and in style file, set AppCompat Theme as your parent:
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>

Try this it will work click on values in resources than open styles.xml file and change this
with following
i was getting the same issue and it is due to the update in the material lib

Related

java.lang.IllegalArgumentException: This component requires that you specify a valid android:textAppearance attribute

I have a com.google.android.material.button.MaterialButton component in one of my layout file and I get this error when I am using the latest version of the Material Components library (com.google.android.material:material:1.0.0-alpha3):
java.lang.IllegalArgumentException: This component requires that you specify a valid android:textAppearance attribute.
It wasn't present in 1.0.0-alpha1. Is this a bug in the library or should I just specify a textAppearance attribute from now?
Does your theme extend from Theme.MaterialComponents? More info about how to ensure all the components will work correctly can be found at https://material.io/develop/android/docs/getting-started/
If you are using any of the MaterialComponent, then your theme must extend from the following theme - Theme.MaterialComponents.Light.DarkActionBar
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
If you want to keep using your old styles but only want to extend from 'Theme.MaterialComponents' then you can use 'Bridge'.
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar.Bridge">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorAccent</item>
<item name="colorAccent">#color/colorPrimaryDark</item>
</style>
if your theme does not extend MaterialComponents theme, and you want to keep the AppCompat theme, use a bridge theme, that would allow you to use material components keeping the AppCompat theme.
change your existing theme from:
<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>
to this:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.Bridge">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
Does my theme extend from Theme.MaterialComponents? Oh yes indeed, and has been since I started using any of the new Material UI stuff.
If all these answers here are as unhelpful to you as they were to me, get ready: The This component requires that you specify a valid android:textAppearance attribute error can be related to an external library specifying android:theme with the same name as the theme you are using, and Android randomly deciding which one to use depending on your build.gradle. In my case the culprit was inside Mobile FFmpeg.
I started encountering this error after working for a week while the build variant was set to a different product flavor and then switching back the original one. What changed meanwhile? After thorough investigation I found the build broke after I split implementation 'com.arthenica:mobile-ffmpeg-min:4.2.2.LTS' in two, for each product flavor where I actually use it like this:
videoImplementation 'com.arthenica:mobile-ffmpeg-min:4.2.2.LTS'
mainImplementation 'com.arthenica:mobile-ffmpeg-min:4.2.2.LTS'
This was enough to trigger This component requires that you specify a valid android:textAppearance attribute for flavor main, while working fine for flavor video. Every main build crashed because my app's theme is named AppTheme and the Mobile FFmpeg manifest also specifies android:theme="#style/AppTheme" (which affects all versions up to 4.2.2). So I renamed my theme, but that resulted in a build error very similar to the one here:
https://github.com/tanersener/mobile-ffmpeg/issues/206
Attribute application#theme value=(#style/ScryptedTheme) from AndroidManifest.xml:37:9-45
is also present at [com.arthenica:mobile-ffmpeg-https:4.2.LTS] AndroidManifest.xml:17:9-40 value=(#style/AppTheme).
Suggestion: add 'tools:replace="android:theme"' to <application> element at AndroidManifest.xml:31:5-95:19 to override.
After adding said tools:replace="android:theme", everything worked again, and the original MaterialComponents error was gone.
But why is it OK for one flavor and not OK for the other? Absolutely no idea. Credit goes to Google's tendency to add the craziest bugs to "stable" releases. At least it's possible to solve very easily with some refactoring.
TL;DR
THIS is the issue: https://github.com/tanersener/mobile-ffmpeg/issues/206
Together with the fact that when two merged manifest specify different themes with the same name, Android will choose one randomly depending on the content of your build.gradle.
Solution: Add a tools:replace="android:theme" to your manifest's <application> tag and change the name of your theme.
Check if your AppTheme inherits from MaterialComponents as specified here.
<style name="Theme.MyApp" parent="Theme.MaterialComponents.Light">
<!-- ... -->
</style>
Remember to check all variants of styles.xml file. This was actually the issue I had.
I had the same problem, I changed my activity theme but it didnt resolved the issue. The i changed my main app theme from AppCompact to Theme.MaterialComponents
<application
android:allowBackup="true"
android:fullBackupContent="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme2">
<activity
android:name=".MainActivity"
android:label="#string/app_name"/>
</application>
Got stucked in this error even if my theme extends Theme.MaterialComponents. I was creating Chips like this :Chip chip = new Chip(getActivity().getBasecontext(), null, R.attr.CustomChipChoice);.
The solution is to change it to Chip chip = new Chip(getActivity(), null, R.attr.CustomChipChoice);.
Hope it helps.
I have included this dependence first
implementation 'com.google.android.material:material:1.2.0-alpha01'
Than I have set my project style as bellow
<style name="AppTheme" parent="Theme.MaterialComponents.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>
Extending Correctly? => Verify your styles!
In my case, I made a dumb auto-complete mistake:
<item name="textInputStyle">#style/Widget.MaterialComponents.Button.OutlinedButton</item>
What I really meant was TextInputLayout.OutlinedBox instead of Button.OutlinedButton:
<item name="textInputStyle">#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox</item>
Unfortunately this typo gives the same misleading error (despite extending the theme correctly):
Caused by: java.lang.IllegalArgumentException: This component requires
that you specify a valid TextAppearance attribute. Update your app
theme to inherit from Theme.MaterialComponents (or a descendant).
...sharing because it took me a long time to spot the error!
If you tried other answers on how to properly set parent theme for your app's theme, and you still get ...requires a value for to be set in your app theme., you may check if you have more than one place, where your app's theme is defined, as you may have separate themes.xml files for specific configuration, API versions etc.
For example:
res/values/themes.xml - default one
res/values-v23/themes.xml - for devices with API >= 23

Android app masthead display

I have created an app using Android Studio 2.3.3, choosing Empty Activity Template. After its creation I went and changed the background color to something like colorAccent and I also changed the colorPrimary to colorAccent in colors.xml.
Now, when I ran the app, following emulator display appeared.
As you can see, it displays my app name, followed by a dark line.
I don't understand where this dark line has come from and how can I get rid of this?
However, this dark line does not appear in Android Studio design mode (see screenshot below).
it is shadow of action bar my friend
to remove this shadow add below lines to your theme under res/values/style
<style name="MYTheme" parent="android:Theme.Holo.Light">
<item name="colorPrimary">#color/colorWhite</item>
<item name="colorPrimaryDark">#color/colorWhite</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="windowContentOverlay">#null</item>
<item name="android:windowContentOverlay">#null</item>
</style>
now add this in manifest file this to your activity
<activity
android:name=".YourActivity"
android:theme="#style/MYTheme"/>
or try this
getSupportActionBar().setElevation(0);

Why does select theme in Android Studio cause my layout become different

i using android studio to start develop apps, but i have some question about "Select Theme" in android studio. First, i noticed i select "NoActionBar" option, the layout will be like
The statusbar has no color, but after when i change to "AppTheme", the layout became
I had double check the code in styles.xml, but there are no changes. I really can't figure out about this. Can anyone explain this to me? Thank in advance.
**I have figured out actually select theme only the preview, it doesn't change my XML layout.
you will find this in styles.xml
<!-- 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>
In your layout, two things are happening here
1. Your layout have a toolbar in its xml. So toolbar always showing.
2. the above pic will give you an idea about how the material theme isapplying with colors.
Hope this helps you.
check the colorPrimary and the colorPrimaryDark in your color.xml file

Android styles.xml windowNoTitle (ActionBarActivity)

I want to hide the title bar (where the activity tile is shown) in my application. I'm doing this by setting the android:windowNoTitle item to true. This works fine for devices with API level 19. I tested it with a device running API level 10 and it only hides the notification bar. The tile bar is still shown.
Here is my res/values/styles.xml
<resources>
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
</style>
</resources>
EDIT: I'm using the AppBaseTheme as the theme in my manifest. There are no other styles.xml files in any other value-vXX folder.
Edit#2: I'm extending an ActionBarActivity for my activity.
try using this
<style name="MyMaterialDialog" parent="Base.Theme.AppCompat.Light.Dialog.MinWidth">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
</style>
remove android prefix!
I tried the android:style/Theme.NoTitleBar.Fullscreen in styles.xml but I got:
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
So I followed the advise to stick to the AppCompat theme, and could hide statusbar and actionbar using the following lines in styles.xml:
<resources>
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
</style>
</resources>
I use 1 theme for all the devices and it works perfectly on API level 8 to 16 (since I only have 5 physical devices). I'm sure it's working on 17-19 devices too.
Make sure that in your Manifest file (in the application section), there is a line like android:theme="#style/AppTheme"
Try using this for your theme:
<style
name="AppBaseTheme"
parent="android:style/Theme.NoTitleBar.Fullscreen"
>
<item name="android:windowNoTitle">true</item>
...
</style>
And remove the styles/themes in the values-xy folders
[EDIT]
Since the AppCompat theme is NOT full screen, by definition, the StatusBar will go away, but not the TitleBar
If you don't need the ActionBar offered by the AppCompat, then you should get rid of the AppCompat as soon as possible: don't bloat your apps with unneeded and unwanted things
For instance, I have a Header Bar and a Footer Bar, but these are simply RelativeLayouts I implemented my own.
And still have the freedom of using the whole screen surface.

Setting transparent background for activity shown as dialog on xml not working on all devices

I have a custom view on an activity that is showed as a dialog.
I applied a custom theme to my activity so its parent is: "#android:style/Theme.Dialog" and I changed the window background to be transparent.
My Manifest.xml:
<activity android:name="com.rev.revcorder.ui.UserAuthenticationDialogActivity" android:screenOrientation="portrait"
android:theme="#style/userAuthenticationDialog">
</activity>
My styles.xml:
<style name="userAuthenticationDialog" parent="#android:style/Theme.Dialog">
<item name="android:windowBackground">#android:color/transparent</item>
</style>
The issue is that it is working fine on my device (Nexus 4 running 4.4) but on other device that is the same as mine (Nexus 4 running 4.4) it is not. Instead, the background is shown in black not transparent.
It only worked when I set it grammatically by adding:
getWindow().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#00000000")));
My question is, what is the difference between setting the window background on my xml style and doing i grammatically ?
Also, how come it is working on my device and not on another same device ?
Thanks for your help
Add 2 more attributes to style like below code:
<style name="userAuthenticationDialog" parent="#android:style/Theme.Dialog">
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:windowIsTranslucent">true</item>
</style>
You can make a Custom Theme for all the devices.
For example, here is the declaration for a custom theme which is simply the standard platforms default light theme. It would go in an XML file under res/values (typically res/values/styles.xml):
<style name="LightThemeSelector" parent="android:Theme.Light">
...
</style>
To have this theme use the newer holographic theme when the application is running on Android 3.0 (API Level 11) or higher, you can place an alternative declaration for the theme in an XML file in res/values-v11, but make the parent theme the holographic theme:
<style name="LightThemeSelector" parent="android:Theme.Holo.Light">
...
Now use this theme like you would any other, and your application will automatically switch to the holographic theme if running on Android 3.0 or higher.
For more information about providing alternative resources, such as themes and layouts, based on the platform version or other device configurations, see the Providing Resources document.
Show below image how can u structure resources.
Update:
Also try this, set below Theme into manifest.xml
android:theme="#android:style/Theme.Translucent.NoTitleBar"

Categories

Resources