I am not sure If this is happening only for me or even for others, here is what is happening:
I have set menu.xml which four icons
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.ylg.default.Home">
<item
android:id="#+id/action_key"
android:icon="#drawable/key"
android:orderInCategory="9999999"
android:title="#string/lock"
app:showAsAction="always" />
<item
android:id="#+id/action_alert"
android:icon="#drawable/bell"
android:orderInCategory="9999999"
android:title="#string/alert_action"
app:showAsAction="always" />
<item
android:id="#+id/action_home"
android:icon="#drawable/home_tool"
android:orderInCategory="9999999"
android:title="#string/office"
app:showAsAction="always" />
<item
android:id="#+id/action_logo"
android:icon="#drawable/rupees"
android:orderInCategory="9999999"
android:title="#string/home"
app:showAsAction="always" />
</menu>
The icons shows properly with ripple effect on my Nexus 5 but the problem is that the title gets cut hence I changed the padding values for icons (Right and left) in my style using:
<style name="Theme.default" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:actionButtonStyle">#style/MyActionButtonStyle</item>
</style>
<style name="MyActionButtonStyle" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:minWidth">40dp</item>
<item name="android:paddingLeft">2dp</item>
<item name="android:paddingRight">2dp</item>
</style>
If I put this the menu icons reduces their spacing between each other but ripple effect is not seen when I touch the icons.
I am not sure why this happening? Anybody there who can help me with this?
Thanks!
The parent you've used for MyActionButtonStyle has no proper background. The parent should be Widget.AppCompat.Light.ActionButton.
<style name="MyActionButtonStyle" parent="Widget.AppCompat.Light.ActionButton">
But anyway that's not a good idea reducing the space between the menu items. Instead, use
app:showAsAction="ifRoom"
So items that do not fit will be put into overflow. This is necessary because there is always a smaller dp screen that Nexus 5 resulting in title being cut even more. The lint should have warned you about this.
Related
I have tried numerous solutions but none seems to work, I have been trying to change the color of the icon I have in a menu, I am working with two activities both of which contains different menus, I have attached two images for references
The image represents the MainActivity Menu, it works fine between light and dark theme
The image represents the SecondActivity Menu, the icons refuses to change its color despite manually specifying the iconTint in the menu xml file
Here is the menu of the secondActivity
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:title="More"
android:icon="#drawable/detail_menu"
android:iconTint="#color/white"
app:showAsAction="always">
<menu>
<item
android:id="#+id/browse_news"
android:title="View Full Article"
android:iconTint="#color/white"
android:icon="#drawable/reading_fullarticle"
app:showAsAction="never" />
<item
android:id="#+id/share_news"
android:title="Share Article"
android:iconTint="#color/white"
android:icon="#drawable/read_sharearticle"
app:showAsAction="never" />
<item
android:id="#+id/save_news"
android:title="Save article"
android:iconTint="#color/white"
android:icon="#drawable/read_savearticle"
app:showAsAction="never" />
</menu>
</item>
Here is an image of how the menu icon is supposed to look like according to the xml, I don't think I have overridden any of the styles in the styles XML. Any clues on why this is happening?
I'm trying to fight the default behaviour of the Widget.AppCompat.Button.Colored style. By default the button is semi transparent. I want it to be opaque.
Here is my code:
Button in layout:
<Button
android:id="#+id/search"
style="#style/Widget.AppCompat.Button.Colored"
android:theme="#style/AccentButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Search"/>
styles.xml
<style name="AccentButton" parent="ThemeOverlay.AppCompat.Light">
<item name="colorAccent">#color/colorAccent</item>
<item name="colorButtonNormal">#f00</item>
</style>
If I remove the style="#style/Widget.AppCompat.Button.Colored" part the button will not turn transparent if disabled.
I've tried to look into the Appcompat/Android source code. No luck though. I can't find the part where it is set to be transparent. The goal is the get a nice solution using mostly AppCompat code. I know I can create a custom drawable button backgroud. I would like to avoid it. Any ideas?
The solution is to use: <item name="android:disabledAlpha">1.0</item> like this:
<style name="AccentButton" parent="ThemeOverlay.AppCompat.Light">
<item name="colorAccent">#color/colorAccent</item>
<item name="colorButtonNormal">#f00</item>
<item name="android:disabledAlpha">1.0</item>
</style>
How I got to this answer
After some struggle I've found btn_colored_material.xml source code.
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false"
android:alpha="?attr/disabledAlpha"
android:color="?attr/colorButtonNormal" />
<item android:color="?attr/colorAccent" />
</selector>
It uses the disabledAlpha attribute. So it was only a matter of using it.
One thing I still don't get is why I have to use it with the android: prefix. I would expect that:
?android:attr/something to be set with <item name='android:something'>(...)
?attr:something to be set with <item name='something'>(...)
My guess is that if Android soruce code code uses it's own attributes it doesn't need the prefix.
I am trying to add some space to the the top of my SwitchPreferenceCompat which is inside of a PreferenceFragmentCompat. Basically I just need some room between it and the top Toolbar, either by expanding its height or with a padding gap without adding a white space that will interfere with the elevation shadow of the Toolbar. I believe I can achieve this by adding a custom style to the SwitchPreferenceCompat, but I am having trouble getting that to work.
Here is what I have tried:
In my styles.xml-
<style name="SwitchPreferenceNew" parent="Preference.SwitchPreferenceCompat.Material">
<item name="android:paddingTop">20dp</item>
</style>
In my app_preferences.xml-
<android.support.v7.preference.SwitchPreferenceCompat
style="#style/SwitchPreferenceNew"
android:defaultValue="false"
android:icon="#drawable/ic_power_settings_new_black_48dp"
android:key="prefsActivate"
android:summary=""
android:title="Activate reminders" />
I think I am just not overriding the style correctly, but I am having trouble finding out how to do it with the SwitchPreferenceCompat. Thank you in advance!
I know this is late but i get result from following code:
my app theme:
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="preferenceTheme">#style/my_preference_theme</item>
</style>
my preference theme:
<style name="my_preference_theme" parent="#style/PreferenceThemeOverlay">
<item name="switchPreferenceCompatStyle">#style/preference_switch_compat</item>
</style>
in my PreferenceSwitchCompat i used layout property and you should create new layout for your view
<style name="preference_switch_compat">
<item name="android:layout">#layout/switch_layout</item>
</style>
this is here you must customize your view:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.SwitchCompat
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/switchWidget"
android:background="#f00"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
hope to help to someone.
As the question states, I'm running into some weird behavior where my left drawables are not given any left padding on an HTC One running Android 4.4.
The layout where I'm seeing this is
<LinearLayout>
<include layout="#layout/search_bar" />
<!-- Some Fragment layout information -->
</LinearLayout>
Inside search_bar I have a Layout which looks like.
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp">
<EditText
android:layout_width="match_parent"
android:layout_height="56dp"
style="#style/SearchBox.SingleSearchBar" />
</FrameLayout>
The SearchBox.SingleSearchBar style looks like (after some massaging of the style hierarchy).
<style name ="SearchBox.SingleSearchBar" parent="#android:style/Widget.TextView">
<item name="android:focusable">false</item>
<item name="android:gravity">center_vertical</item>
<item name="android:singleLine">true</item>
<item name="android:lines">1</item>
<item name="android:imeOptions">actionSearch|flagNoExtractUi</item>
<item name="android:layout_centerHorizontal">true</item>
<item name="android:selectAllOnFocus">true</item>
<item name="android:drawableLeft">#drawable/gray_magnifying_glass</item>
<item name="android:scrollHorizontally">true</item>
<item name="android:paddingLeft">#dimen/search_drawable_padding</item>
<item name="android:paddingRight">#dimen/search_drawable_padding</item>
<item name="android:paddingTop">#dimen/search_drawable_padding</item>
<item name="android:paddingBottom">#dimen/search_drawable_padding</item>
<item name="android:drawablePadding">#dimen/search_drawable_padding</item>
<item name="android:maxLines">1</item>
<item name="android:background">#drawable/search_bar_selector</item>
<item name="android:textAppearance">#style/TextAppearanceSearchBox</item>
<item name="android:textCursorDrawable">#drawable/search_box_cursor</item>
</style>
On every device that I've seen except for the HTC One, this runs fine: the left drawable is padded in search_drawable_padding dips from the left, and there is appropriate padding between the drawable and the text. However, for some reason, on the HTC One, there is no padding between the left edge of the text box and the drawable.
I logged the value for both getPaddingLeft() and getPaddingTop and found that on the HTC One they are 0px, while on a Samsung GS4 they are 48 pixels, which makes sense given that search_drawable_padding is 16dips.
Is there any way around this? Am I missing something really stupid that is forcing me to call setPadding in code in order to make this work?
Please check your background drawable search_bar_selector,
<item name="android:background">#drawable/search_bar_selector</item>
Setting the background can reset the value of padding to 0 (see here).
One solution to fix this is to set the padding value again in file search_bar_selector, (Good solution, since you need not to set padding value programmatically).
<padding android:bottom="#dimen/search_drawable_padding" android:left="#dimen/search_drawable_padding" android:right="#dimen/search_drawable_padding" android:top="#dimen/search_drawable_padding" />
I have the following dropdown:
<style name="SpinnerDropdown" parent="android:style/Widget.ListView.DropDown">
<item name="android:background">#04384f</item>
<item name="android:divider">#000000</item>
<item name="android:dividerHeight">1dp</item>
</style>
I want to change the color of the currently pressed item. This color is currently orange (#feba21) and I want it to be something else. I haven't set it anywhere so I assume it's inherited from Widget.ListView.Dropdown
How can I change it, and more importantly where can I find Windget.ListView.Dropdown in the SDK so I can see what properties it has?
I tried adding the selector_spinner_option:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="#color/bright_positive" />
<item android:drawable="#color/dimmer_positive" />
</selector>
as the background of SpinnerDropdown, but what it does is change all the other items when one item is pressed - while that item remains orange!!
Orange is not the background of dropdown item. It is a color of selector. It is easy to change it by the attribute listSelector
The following code will change orange to green
<style name="SpinnerDropdown" parent="android:style/Widget.ListView.DropDown">
<item name="android:background">#04384f</item>
<item name="android:divider">#000000</item>
<item name="android:listSelector">#00ff00</item>
<item name="android:dividerHeight">1dp</item>
</style>
Hope it help.