Setting button background via theme makes the button unclickable - android

Like the title indicates, when setting background of a button via theme, the button stops responding. I believe it is an issue on a few android versions, since my Nexus 4 running KitKat has no issue, however my HTC Desire S running 2.3.5 has it happenning. By the way, I am using the HoloEverywhere 2.0 atm. What is the problem?
The way I set the theme is the following:
<style name="AppTheme" parent="#style/Holo.Theme.Light.DarkActionBar">
<item name="android:buttonStyle">#style/MyButtonStyle</item>
</style>
The button style is the following:
<style name="MyButtonStyle" parent="android:style/Widget.Holo.Light.Button">
<item name="android:background">#drawable/button_yellow</item>
</style>
This works on the N4, but will NOT work on the HTC Desire S. However, if I set the same background directly on the button, it is working well on the HTC too, like this:
<Button
android:id="#+id/example_button"
android:text="Example"
android:gravity="center"
android:onClick="onClickEvent"
android:background="#drawable/button_yellow"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
Any idea what is going wrong?

You should use Holo.Button.Light as parent in your custom button style.

Related

Button design over Android OS versions

I'm trying to polish up some details about my app and I'm stuck on design of android Button widget. Up from Android 5.0 everything is fine with simple system Button, but problem starts when I start my app on lower versions - specifically 4.4.2 . System Button has no effect on click which is of course wrong UX. I'd like to avoid making multiple layouts for different android version and I think there is some way to solve this without making my own selector and using in in pre-Lollipop layouts, but I just can't find it. My Button layout looks as follows :
<Button
android:id="#+id/some_id"
android:layout_width="wrap_content"
android:layout_height="#dimen/size_48dp"
android:paddingLeft="#dimen/margin_32dp"
android:paddingRight="#dimen/margin_32dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:gravity="center"
app:backgroundTint="#color/colorAccent"
android:textColor="#color/white"
android:text="#string/some_text"/>
As i said, on all post-lollipop version it has some effect (from android 6 it's ripple, before it just changes tint) but on Kitkat id does nothing. I tried using AppCompatButton, all sort of colorControlNormal, colorButtonNormal and I don't know what in styles but to no avail. Is there some "easy" way to solve this ?
You can create styles in both styles.xmlad v21 styles.xml
Below is code snippet of v21 styles.xml
<style name="ButtonRed" parent="Theme.AppCompat">
<item name="android:colorButtonNormal">#color/primary_red</item>
<item name="android:colorControlHighlight">#color/primary_red_dark</item>
<item name="android:textColor">#color/dash_title_color_white</item>
</style>
Below is code snippet of styles.xml
<style name="ButtonRed" parent="Base.Widget.AppCompat.Button">
<item name="colorButtonNormal">#color/primary_red</item>
<item name="colorControlHighlight">#color/primary_red_dark</item>
<item name="android:textColor">#color/dash_title_color_white</item>
</style>
Then you can use these styles as theme as given below
<Button
android:layout_width="wrap_content"
android:theme="#style/ButtonRed"
android:layout_height="wrap_content"
android:text="#string/recharge"
/>
Ripple type animation will only work from lollipop onwards. Below that the button will change colour state accordingly
Animations in material design give users feedback on their actions and provide visual continuity as users interact with your app. The material theme provides some default animations for buttons and activity transitions, and Android 5.0 (API level 21) and above lets you customize these animations and create new ones:
Touch feedback
Circular Reveal
Activity transitions
Curved motion
View state changes
Touch feedback in material design provides an instantaneous visual confirmation at the point of contact when users interact with UI elements. The default touch feedback animations for buttons use the new RippleDrawable class, which transitions between different states with a ripple effect.
Verify this Page
https://developer.android.com/training/material/animations.html#Touch
ANd Also these Answers will help you
how to create ripple effect for pre-lollipop

Normal font appears italic on some devices. Why and how to fix?

The problem is that text in TextView looks fine on Android emulator, but it doesn't on the actual device. This is not my device and I'm not familiar with Android system, so I don't know if it's somehow overridden by system settings.
Here is how it looks on the emulator:
And here is how it looks on the device:
TextView:
<TextView
android:id="#+id/text_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="#style/AppTheme.Text.StepperHeader"
android:text="Header"/>
Style:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- No text-related settings here. -->
</style>
<style name="AppTheme.Text">
<item name="android:textColor">#1F1F1F</item>
</style>
<style name="AppTheme.Text.StepperHeader">
<item name="android:textSize">14sp</item>
</style>
If the problem is in AppCompat theme as a parent — which one should I use instead?
I want a consistent app look on all devices. Can you explain why it's happening and how to fix it?
To be able to get same font result on (almost) every device, use a custom font. You can download one from websites like DaFont, etc. Then, you can apply your custom font easily (and without a need to get into the details of Android styles) to your UI widgets using Calligraphy library. See its piece-of-cake documentation for examples usage.

App Theme's TextColor being ignored on Samsumg Galaxy Tab 4

I have an android app where I have set the text and background colours as follows in the theme in styles.xml:
<style name="MyAppTheme" parent="Theme.AppCompat.Light">
<item name="colorPrimary">#28abe3</item>
<item name="colorPrimaryDark">#0f92ca</item>
<item name="colorAccent">#0f92ca</item>
<item name="android:textColor">#8a000000</item>
<item name="android:textColorPrimary">#de000000</item>
<item name="android:colorBackground">#fffafafa</item>
<item name="android:textColorSecondary">#8a000000</item>
<item name="android:textColorTertiary">#8a000000</item>
</style>
This works great on every device I can find to test it on. However, I have some users running the app on a Samsung Galaxy Tab 4, who are reporting that some of the text views are showing text in a very light shade of grey, almost indistinguishable from the background, instead of the very dark grey specified through the theme. This doesn't affect every TextView in the app, but an example one is shown below:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text Here"
android:id="#+id/problematicTextView"
android:layout_weight="1"
android:minHeight="25dp"
style="#android:style/TextAppearance.DeviceDefault.Medium" />
I've tried everything I can think of short of buying a Galaxy Tab 4 to debug this by trial and error, but to no avail. The only distinguishing feature between TextView that appear with the correct dark grey text as opposed to those which appear in the very light grey color is the line:
style="#android:style/TextAppearance.DeviceDefault.Medium"
The ones which work correctly have:
style="#android:style/TextAppearance.DeviceDefault.Small"
but as I understand it, this is only meant to affect the text size rather than color.
What am I missing to style the TextView text colors correctly in a way that works on all devices (targeting API level 16+)?
If you want a consistent theme across all devices, you should avoid using any DeviceDefault styles as those are the ones customized by individual manufacturers.
I'd instead suggest using one of the AppCompat TextAppearance styles such as Theme.AppCompat.Medium.

ToggleButton dissapears when make background transparent

I try to make some XML layout in Android Studio. I need my app to be compatible with API 10 and higher. My layout have some switch buttons but Switch is for API 14 or higher. It is why I decide to use Toggle Button instead.
I have made custom selector drawable with two states. And problem starts now.
When I make XML like this:
<ToggleButton
android:id="#+id/reminderRepeatToggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/toggleButton"
android:button="#drawable/ic_toggle_bg"
android:background="#android:color/transparent"/>
It works perfectly on android higher than API 10 but on 10 ToggleButton simply disappear.
I also tried something like this:
<ToggleButton
android:id="#+id/reminderRepeatToggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/toggleButton"
android:background="#drawable/ic_toggle_bg"/>
and it works on API 10 but it looses it proportions. Any idea how to overcome this? Or maybe you advice different approach to the problem? (not making Toggle but something different).
Thanks for help!
style:
<style name="toggleButton">
<item name="android:buttonStyleToggle">#style/Widget.Button.Toggle</item>
<item name="android:textOn">#string/blank</item>
<item name="android:textOff">#string/blank</item>
</style>
<style name="Widget.Button.Toggle" parent="android:Widget">
<item name="android:background">#drawable/ic_toggle_bg</item>
<item name="android:disabledAlpha">?android:attr/disabledAlpha</item>
</style>

Style ActionMode

I am using ActionBarSherlock and trying to style ActionMode. I can change background and done button using these attributes in my style:
<item name="android:actionModeCloseDrawable">#drawable/abs__ic_cab_done_holo_dark</item>
<item name="android:actionModeBackground">#drawable/actionbar_bg</item>
But I can not figure out how to set the color of the vertical line just next to the done button. Does anyone know how to do this?
I solved it with this code in my theme:
<item name="android:actionModeCloseButtonStyle">#style/action_button_done</item>
And the style action_button_done just sets the background drawable:
<style name="action_button_done" parent="Widget.Sherlock.ActionButton.CloseMode">
<item name="android:background">#drawable/abs__btn_cab_done_holo_dark</item>
</style>
Warning
This should be a simple thing to do. And it was, but for some reason htc decided to put an extra layer on top of the button that makes it impossible to style it. I was just lucky that I tried deploying on my friends samsung galaxy nexus and noticed that it actually worked. I only used htc one x, so don't know if it is the same on other htc devices.

Categories

Resources