Material Design custom view theme - android

I am trying to have a default theme with a button. When I do this the button no longer ripples. I believe I need to set a proper parent on the btn_normal style but I can not find the appropiate theme.
btn_normal style works fine if I just apply it via a style to the button directly.
I have tried tons of parents and none of them have worked. Let me know if you have ran into this. Thanks.
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:buttonStyle">#style/btn_normal</item>
</style>
<style name="btn_normal">
</style>

You should use RippleDrawable third party library. By that, you can give Ripple effect for Android 7+ version.

Related

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

Custom style for buttons not work on pre-5.0 devices [duplicate]

I am using the AppCompat theme and I want set the minHeight attribute on my buttons:
<style name="Theme.MyTheme" parent="Theme.AppCompat">
<item name="android:buttonStyle">#style/MyButtonStyle</item>
</style>
<style name="MyButtonStyle" parent="...?">
<item name="android:minHeight">60dp</item>
</style>
However, there is no Widget.AppCompat.Button style to set as the parent for MyButtonStyle. If I use android:Widget.Button, then all my buttons look like the old crappy style. I tried various other AppCompat themes like TextAppearance.AppCompat.Button, but they do not work.
Leaving out a parent theme for the button style also causes the button not to be styled correctly.
How can I customize the default Theme.AppCompat buttonStyle?
You can have Base.MyButtonStyle extend android:Widget.Holo.Button on API 14+ (in res/values-v14/styles.xml) and android:Widget.Material.Button on API 21+ (in res/values-v21/styles.xml. This style will change according to the device system version. Put your platform specific modifications here.
Then have MyButtonStyle extend Base.MyButtonStyle and define the android:minHeight here (in res/values/styles.xml). This will apply to all platforms.
You buttons then can use style MyButtonStyle.
This example assumes your minimum SDK is 14.
And yes, there's no appcompat-v7 button style (well, at least not yet).
EDIT
This assumes you're OK with Holo button on platforms older than Lollipop. It feels unobtrusive and if you can do without ripples, it should be just fine. If you want ripples I suggest you google for a third party lollipop button library.
To answer my own question, it appears AppCompat does not in fact support the Button widget presently:
AppCompat provides similar behaviour on earlier versions of Android
for a subset of UI widgets:
Everything provided by AppCompat’s toolbar (action modes, etc)
EditText
Spinner
CheckBox
RadioButton
Switch (use the new android.support.v7.widget.SwitchCompat)
CheckedTextView
The only workaround I see would be to recreate the Material button style from the Android source code, a task which extends outside the scope of my desire.
Custom Button Style With AppCompat +22
in your styles.xml
<style name="Button.Tinted" parent="Widget.AppCompat.Button">
<item name="colorButtonNormal">YOUR_TINT_COLOR</item>
<item name="colorControlHighlight">#color/colorAccent</item>
<item name="android:textColor">#android:color/white</item> </style>
in your layout.xml
<Button
android:id="#+id/but_next"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/but_continue"
android:theme="#style/Button.Tinted" />
With new MaterialComponent it is convenient to use com.google.android.material.button.MaterialButton instead of regular Button.
But to style it, there is used the different attribute in the theme
- materialButtonStyle, with this parent theme Theme.MaterialComponents.DayNight.NoActionBar.
Then the theme should look like this:
<style name="NewAppTheme"
parent="Theme.MaterialComponents.DayNight.NoActionBar">
.......
<-- IMPORTANT if you are using com.google.android.material.button.MaterialButton to style them use this parameter
<item name="materialButtonStyle">#style/ButtonStyle</item>
</style>
And in ButtonStyle you can change button attributes like this:
<style name="ButtonStyle" parent="Widget.MaterialComponents.Button.UnelevatedButton">
<item name="android:minHeight">60dp</item>
</style>
Remove the android:
<style name="Theme.MyTheme" parent="Theme.AppCompat">
<item name="buttonStyle">#style/MyButtonStyle</item>
</style>
https://stackoverflow.com/a/32363833

Android colorControlNormal xml attributes doesn't work pre-Lollipop

I've been trying to change the color of the EditText line on the bottom, but my EditText still doesn't wanna change the color, but it's using the style from Material.
I've tried to change the color following these answer: link
So I have an EditText with the Material form but not the colors I've set.
I've put appcompat-v7 in my Gradle config file, and it's already working for the color primary.
<style name="AppBaseTheme.MiddleTheme.Widget.EditText" parent="Theme.AppCompat.Light">
<item name="colorPrimary">#color/middle_primary</item>
<!-- Those 3 lines are staying in red war in IntelliJ but it does build the project -->
<item name="android:colorControlNormal">#color/middle_sqool_primary</item>
<item name="android:colorControlActivated">#color/middle_sqool_primary</item>
<item name="android:colorControlHighlight">#color/middle_sqool_primary</item>
</style>
You have to set the colorControlActivated, colorControlHighlight and colorControlNormal in your app theme (or activity theme) not in your edittext style.
Something like this:
<style name="Theme.App.Base" parent="Theme.AppCompat.Light">
<item name="colorControlNormal">#color/middle_sqool_primary</item>
<item name="colorControlActivated">#color/middle_sqool_primary</item>
<item name="colorControlHighlight">#color/middle_sqool_primary</item>
</style>
As a workaround, try using android.support.v7.widget.AppCompatEditText rather than EditText. You should always use that for programmatically created views.
Pretty sure you made it, but be sure you are editing themes in the values folder and not in the values-v21 one (if any).
I had a similar issue. Wanted to change the highlight colour of the menu items. And none of these attributes didn't work (Support Library v25.0.0).
The only attribute that allowed me to change colour on Pre-L devices is this:
<item name="actionBarItemBackground">#drawable/YOUR_DRAWABLE</item>
I stopped searching for further workarounds because it's obvious that Support Library is NOT ready for production code.

How to Customize AppCompat Material Button Style?

I am using the AppCompat theme and I want set the minHeight attribute on my buttons:
<style name="Theme.MyTheme" parent="Theme.AppCompat">
<item name="android:buttonStyle">#style/MyButtonStyle</item>
</style>
<style name="MyButtonStyle" parent="...?">
<item name="android:minHeight">60dp</item>
</style>
However, there is no Widget.AppCompat.Button style to set as the parent for MyButtonStyle. If I use android:Widget.Button, then all my buttons look like the old crappy style. I tried various other AppCompat themes like TextAppearance.AppCompat.Button, but they do not work.
Leaving out a parent theme for the button style also causes the button not to be styled correctly.
How can I customize the default Theme.AppCompat buttonStyle?
You can have Base.MyButtonStyle extend android:Widget.Holo.Button on API 14+ (in res/values-v14/styles.xml) and android:Widget.Material.Button on API 21+ (in res/values-v21/styles.xml. This style will change according to the device system version. Put your platform specific modifications here.
Then have MyButtonStyle extend Base.MyButtonStyle and define the android:minHeight here (in res/values/styles.xml). This will apply to all platforms.
You buttons then can use style MyButtonStyle.
This example assumes your minimum SDK is 14.
And yes, there's no appcompat-v7 button style (well, at least not yet).
EDIT
This assumes you're OK with Holo button on platforms older than Lollipop. It feels unobtrusive and if you can do without ripples, it should be just fine. If you want ripples I suggest you google for a third party lollipop button library.
To answer my own question, it appears AppCompat does not in fact support the Button widget presently:
AppCompat provides similar behaviour on earlier versions of Android
for a subset of UI widgets:
Everything provided by AppCompat’s toolbar (action modes, etc)
EditText
Spinner
CheckBox
RadioButton
Switch (use the new android.support.v7.widget.SwitchCompat)
CheckedTextView
The only workaround I see would be to recreate the Material button style from the Android source code, a task which extends outside the scope of my desire.
Custom Button Style With AppCompat +22
in your styles.xml
<style name="Button.Tinted" parent="Widget.AppCompat.Button">
<item name="colorButtonNormal">YOUR_TINT_COLOR</item>
<item name="colorControlHighlight">#color/colorAccent</item>
<item name="android:textColor">#android:color/white</item> </style>
in your layout.xml
<Button
android:id="#+id/but_next"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/but_continue"
android:theme="#style/Button.Tinted" />
With new MaterialComponent it is convenient to use com.google.android.material.button.MaterialButton instead of regular Button.
But to style it, there is used the different attribute in the theme
- materialButtonStyle, with this parent theme Theme.MaterialComponents.DayNight.NoActionBar.
Then the theme should look like this:
<style name="NewAppTheme"
parent="Theme.MaterialComponents.DayNight.NoActionBar">
.......
<-- IMPORTANT if you are using com.google.android.material.button.MaterialButton to style them use this parameter
<item name="materialButtonStyle">#style/ButtonStyle</item>
</style>
And in ButtonStyle you can change button attributes like this:
<style name="ButtonStyle" parent="Widget.MaterialComponents.Button.UnelevatedButton">
<item name="android:minHeight">60dp</item>
</style>
Remove the android:
<style name="Theme.MyTheme" parent="Theme.AppCompat">
<item name="buttonStyle">#style/MyButtonStyle</item>
</style>
https://stackoverflow.com/a/32363833

How can I force my Widgets to use a dark theme?

In my application, I used Theme.Holo.Light to make the ActionBar look light and I am pretty pleased with the result.
The only problem is that all my widgets (EditText, Spinner, etc..) are acting like the background was white, while I set it a dark blue:
Is there an easy way in the style.xml file where I can force everything to act like the theme was dark?
I know that I could theme the text color, background resources, etc.. But this would be a huge work.
Thank a lot for any hint that could help me to achieve that easily.
Edit: what sounds the best solution, but not working:
<style name="AppBaseTheme" parent="#android:Theme.Holo">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
</style>
To solve this (the easy way) you should use Theme.Holo. And Change the actionbar to Theme.Holo.Light.
extend theme:
<style name="MyTheme.Dark" parent="android:Theme.Holo.Light.ActionBar"></style>
use getActionBar().getThemedContext() as the context for inflating your views.
You can use Holoeverywhere library to achieve your result.
HoloEveryWhere

Categories

Resources