I am trying to stylize the TextInputLayout with an outline. But when I try to use #style/Widget.MaterialComponents.TextInputLayout.OutlinedBox in style attribute my app crashes with this exception:
Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).
Here is the TextInputLayout theme I want to use OutlinedBox
It was working fine but suddenly this error appeared during development
<style name="LoginTextInputLayoutStyle" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense">
<item name="boxStrokeColor">#color/text_input_box_stroke</item>
</style>
Global App Theme
<!-- Base application No Action bar 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>
<item name="android:fontFamily">#font/opensans_regular</item>
</style>
As reported in the error:
Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant)
You have to change the app theme to a Material Components Theme like:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- ... -->
</style>
Related
i have a dialog activity and want to remove the action bar from it , and anther dialog activity but just want to change the color of its action bar >>
i tried to change the theme and style but nothing change also.
<style name ="Dialog" parent="Theme.AppCompat.Dialog">
<item name="windowActionBar">false</item>
</style>
and the other style is
<style name ="coloredDialog" parent="Theme.AppCompat.Dialog">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="windowActionBar">false</item>
</style>
also i have tried to use
getSupportActionBar().hide()
but their some is error then and the app is closed suddenly
I've tride to set another color for my actiobar quite a while now.
I've search on google and tried multiple solutions. but non of them have worked out for me.
The code i got now is:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme"
parent="#android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar"
parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#cac09f</item>
</style>
</resources>
This causes my app to crash and displays this:
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
I then tried to set the theme to "Theme.Appcompat" but this wont change the color of the actionbar.
Does anyone know a solution for this?
I run this on a phone running android 4.4.4.
My project is for API 16 and higher (4.1)
You're using an activity from the support package (AppCompatActivity), it can only use compatibility themes (Theme.AppCompat).
The reason why setting a custom action bar background didn't work, is because you also need to use compatibility attributes:
<style name="AppTheme" parent="Theme.AppCompat">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/my_red</item>
<item name="background">#color/my_red</item>
</style>
<color name="my_red">#cac09f</color>
guy I think that would be better you to use a toobar, because it is easier of work.
use this code in your xml:
<android.support.v7.widget.Toolbar
android:id="#+id/tbMain"
android:layout_width="match_parent"
app:theme="#style/style_toobar"
android:layout_height="?attr/actionBarSize"
/>
in the style.xml use this:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorPrimary</item>
</style>
<style name="style_toobar" parent="Theme.AppCompat">
<item name="popupTheme">#style/Theme.AppCompat.Light</item>
<item name="colorControlNormal">#color/colorAccent</item>
</style>
in the activity use:
Toobar tbMain = (Toobar)findViewById(R.id.tbMain);
setSupportActionBar(tbMain);
Im trying to create a toolbar but im getting error. I searched and didnt found solution. This is the error:
The following classes could not be found: android.support.v7.widget
my api version is 16.
This is my styles.xml file:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/ColorPrimary</item>
<item name="colorPrimaryDark">#color/ColorPrimaryDark</item>
<!-- Customize your theme here. -->
</style>
I'm using Android Studio and I have this error during the build of the project:
:app:mergeDebugResources FAILED Error:Execution failed for task
':app:mergeDebugResources'.
Unsupported node 'item' in file C:\Users\Mh2\Desktop\IlMartino2doppiofinal\app\src\main\res\values\styles.xml
I tried to clean and rebuild the project but it seems not to be the solution.
Here there is my styles.xml file:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"/>
<!-- Customize your theme here. -->
<item name="homeAsUpIndicator">#drawable/ic_drawer</item>
<item name="android:homeAsUpIndicator">#drawable/ic_drawer</item>
<!-- colorPrimary is used for the default action bar background -->
<item name="colorPrimary">#color/black</item>
<!-- colorPrimaryDark is used for the status bar
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
-->
<!-- colorAccent is used as the default value for colorControlActivated
which is used to tint widgets -->
<!-- You can also set colorControlNormal, colorControlActivated
colorControlHighlight & colorSwitchThumbNormal. -->
<item name="colorControlNormal">#color/purple</item>
<item name="colorControlActivated">#color/red</item>
<item name="colorControlHighlight">#color/darkred</item>
<item name="colorSwitchThumbNormal">#color/darkorange</item>
</resources>
How can I find a solution?
here:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"/>
you closed it with />
You should make it like
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item........
</style>
I want to achieve a somewhat orange color for my actionbar. The problem is, I am using an appcompat theme for my app:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
</style>
<style name="menu_labels_style">
<item name="android:background">#drawable/fab_label_background</item>
<item name="android:textColor">#color/white</item>
</style>
</resources>
So the usual way with:
<resources>
<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#F39530</item>
</style>
</resources>
(for example), won't work. So how do I change the color of the actionbar in an AppCompat theme?
Use colorPrimary to set the color, as in
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- colorPrimary is used for the default action bar background -->
<item name="colorPrimary">#color/background_green</item>
<!-- colorPrimaryDark is used for the status bar -->
<item name="colorPrimaryDark">#color/background_green</item>
<!-- colorAccent is used as the default value for colorControlActivated,
which is used to tint widgets -->
<item name="colorAccent">#color/darkgreen_activeTextColor</item>
<style>
See also this blog post from google devs
AppCompat v21 — Material Design for Pre-Lollipop Devices