Styled Spinner shows dropdown list as dialog - android

after styling my spinner, the dropdown list popup like dialogs,
i tried to set
<item name="android:spinnerMode">dropdown</item>
but the result was like this
i don't like this shadow .
and when i remove the previous line ; i get this result
here is my spinner part of style.xml
<style name="MyTheme.SpinnerAppTheme" parent="android:Widget.Spinner">
<item name="android:background">#drawable/apptheme_spinner_background_holo_dark</item>
<item name="android:spinnerMode">dropdown</item><!--i really don't like the result of this line-->
<item name="android:dropDownListViewStyle">#android:style/Widget.Spinner.DropDown</item>
</style>
the question is How to get back the default dropdown style

i solved it by adding this
</style>
<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:dropDownListViewStyle">#style/MyTheme.MySpinnerStyle</item>
</style>
<style name="MyTheme.MySpinnerStyle" parent="android:style/Widget.Holo.Light.ListView.DropDown">
<item name="android:itemBackground">#fff</item>
<item name="android:dividerHeight">1dp</item>
</style>
The secret is in ".Holo.light"

Related

Android datepicker dialog title pillarboxed

I'm trying to style the datepicker dialog. So far I managed to change the background and button color. But as you can see in the image below, the title is sort of 'pillar-boxed'.
My datepicker dialog with the dark boxes left and right of the title:
My xml code so far (values/styles.xml)
<style name="PickerDialogTheme_dark" parent="Theme.AppCompat.Dialog">
<item name="android:background">#color/colorBackground_bgreen</item>
<item name="android:buttonBarButtonStyle">#style/ButtonColor</item>
</style>
<style name="ButtonColor">
<item name="android:background">#color/colorBackground_bgreen</item>
</style>
In java it is just a regular datepicker dialog constructor with the theme set to PickerDialogTheme_dark and I'm trying to get this to work on pre Lollipop versions.
So hope you guys know how to get rid of this pillar-boxed title. If possible without using fragments and all in xml would be favourable :)
Fixed it finally after searching some more on the internet!
How my final xml code looks now:
<style name="PickerDialogTheme_dark" parent="Theme.AppCompat.Dialog">
<item name="android:gravity">center</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:alertDialogStyle">#style/DialogBackground_dark</item>
<item name="android:windowMinWidthMajor">#android:dimen/dialog_min_width_major</item>
<item name="android:windowMinWidthMinor">#android:dimen/dialog_min_width_minor</item>
</style>
<style name="DialogBackground_dark">
<item name="android:topDark">#color/colorAccent_bgreen</item>
<item name="android:centerDark">#color/colorAccent_bgreen</item>
<item name="android:bottomDark">#color/colorAccent_bgreen</item>
<item name="android:bottomMedium">#color/colorAccent_bgreen</item>
</style>
This is how it looks like now

What style would I need for an AlertDialog to bold?

I have an AlertDialog with buttons which I'd like to set to bold. I find the default style to be very thin:
but when I set the style as such:
<style name="DialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:textColorPrimary">#color/gray_dark</item>
<item name="colorAccent">#color/blue</item>
<item name="android:buttonStyle">#style/buttonStyle</item>
</style>
<style name="buttonStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:textStyle">bold</item>
</style>
I find the result to be, erhm, much bolder than I'd like:
I was aiming for something like this:
The screenshot is from WhatsApp. Are they using a different font or is it something I can replicate just by styling my XML file?
Based on the answer here, it seems that the correct style for what I want to achieve is adding these lines to the button style:
<item name="android:fontFamily">sans-serif-medium</item>
<item name="android:textStyle">normal</item>
Now I have the wanted "not so bold" look!

Set text size of menu items in popup menu

I have created options using customized popup menu.
Now, I want to set the text size of menu items. I am getting default text size this time.
How can I achieve this? I don't want to use popup window. Is it possible to achive this using popup menu only?
I had the same problem. You can change the text size and color by adding this code to styles.xml and use it in manifest file. For me it worked.
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:popupMenuStyle">#style/PopupMenu</item>
<item name="android:textAppearanceLargePopupMenu"> #style/myPopupMenuTextAppearanceLarge</item>
<item name="android:textAppearanceSmallPopupMenu"> #style/myPopupMenuTextAppearanceSmall</item>
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<style name="PopupMenu" parent="#android:style/Widget.PopupMenu">
<item name="android:popupBackground">#android:color/white</item>
<item name="android:textColor">#FF01F0</item>
<item name="android:textSize">12sp</item>
</style>
<style name="myPopupMenuTextAppearanceSmall" parent="#android:style/TextAppearance.DeviceDefault.Widget.PopupMenu.Small">
<item name="android:textColor">#545656</item>
<item name="android:textSize">15sp</item>
</style>
<style name="myPopupMenuTextAppearanceLarge" parent="#android:style/TextAppearance.DeviceDefault.Widget.PopupMenu.Large">
<item name="android:textColor">#545656</item>
<item name="android:textSize">25sp</item>
</style>
You can use something like the below in the manifest file
<activity
android:name=".ActivityName"
android:theme="#style/styleName"/>

Android Spinner style top divider

I'm trying to change the style for the Spinner's top divider, but without success.
I can only get that to work:
http://s18.postimg.org/qbg7920mh/spinner.png
Is is possible? What item should I modify?
<style name="AppTheme" parent="AppBaseTheme">
<!--item name="android:spinnerItemStyle">#style/SpinnerItem</item-->
<!--item name="android:spinnerDropDownItemStyle">#style/SpinnerDropDownItem</item-->
<!--item name="android:dropDownItemStyle">#style/TestSpinnerItemStyle</item-->
<item name="android:dropDownListViewStyle">#style/TestSpinnerStyle</item>
</style>
<style name="TestSpinnerItemStyle" parent="android:style/Widget.ListView.DropDown">
<item name="android:divider">#00b54a</item>
<item name="android:dividerHeight">5dp</item>
</style>
By looking at your code, there must be an obvious error!
Rename TestSpinnerItemStyle to TestSpinnerStyle in second part like:
<style name="TestSpinnerStyle" parent="android:style/Widget.ListView.DropDown">
...
</style>

Android - change dialog title style of all dialogs in application

Is there a way I can change all the alert dialogs appearing in my Android application? I want to change the dialogs that are system generated as well (like the Edit Text dialog that opens up when you long tap on any EditText). I want to change the title font color and size of all the dialogs in my app.
Is there a way to do it?
I have tried setting android:alertDialogTheme in my theme. But it seems to be not working. Code following -
<style name="Theme.DLight" parent="android:Theme.Light.NoTitleBar">
<item name="android:alertDialogTheme">#style/DialogStyle</item>
</style>
and
<style name="DialogStyle" parent="android:Theme" >
<item name="android:windowBackground">#drawable/background_holo_light</item>
<item name="android:textColor">#014076</item>
</style>
EDIT
I'm not invoking a dialog from my code. It's just the default dialog
that appears when you long click on any EditText. Generally it
contains the keyboard options like Select word, Select all, Input
method etc.
In you dialog theme, the attribute you need to modify windowTitleStyle. There, reference a style for your title and define a text appearance for this title. For example, to display your title red and bold:
<style name="AppTheme" parent="#android:style/Theme.Holo">
...
<item name="alertDialogTheme">#style/AppTheme.AlertDialog</item>
</style>
<style name="DialogStyle" parent="#style/Theme.Holo.Dialog.Alert">
...
<item name="android:windowTitleStyle">#style/DialogWindowTitle_Custom</item>
</style>
<style name="DialogWindowTitle_Custom" parent="#style/DialogWindowTitle_Holo">
<item name="android:maxLines">1</item>
<item name="android:scrollHorizontally">true</item>
<item name="android:textAppearance">#style/TextAppearance_DialogWindowTitle</item>
</style>
<style name="TextAppearance_DialogWindowTitle" parent="#android:style/TextAppearance.Holo.DialogWindowTitle">
<item name="android:textColor">#android:color/holo_red_light</item>
<item name="android:textStyle">bold</item>
</style>
If you want to style a little bit more your AlertDialog, I wrote a blog post detailing the steps.
In styles.xml:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
//All your other styles and add the one mntioned below.
<item name="alertDialogTheme">#style/AlertDialogStyle</item>
</style>
In the styles of AlertDialog add:
<style name="AlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="colorAccent">#color/colorAccent</item>
<item name="android:textColorPrimary">#color/primary_text</item>
<item name="android:editTextColor">#color/primary_text</item>
<item name="android:background">#color/white</item>
<item name="android:windowTitleStyle">#style/TextAppearance.AppCompat.Title</item>
</style>
windowTitleStyle is important to add as it will give your title that effect that you need.
Now simply use this Theme in your AlertDialog in any activity that you want like below:
AlertDialog.Builder dialog = new AlertDialog.Builder(this, R.style.AlertDialogStyle);

Categories

Resources