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"/>
Related
Currently I am working on a little android app. I try to change the background color of the ActionBar's dropdown menu. So far I was only able to change the background color of the ActionBar itself, but not of the dropdown menu. It simply does not change the color. Here is some code from my styles.xml:
<style name="AppBaseTheme" parent="Theme.AppCompat.Light"></style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:actionBarStyle">#style/MyActionBarStyle</item>
<item name="actionBarStyle">#style/MyActionBarStyle</item>
<item name="android:actionDropDownStyle">#style/MyActionDropDownStyle</item>
</style>
<style name="MyActionBarStyle" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/background_color_action_bar</item>
<item name="background">#color/background_color_action_bar</item>
</style>
<style name="MyActionDropDownStyle" parent="#style/Widget.AppCompat.Light.Spinner.DropDown.ActionBar">
<item name="background">#color/background_color_action_bar</item>
<item name="android:background">#color/background_color_action_bar</item>
<item name="android:popupBackground">#color/background_color_action_bar</item>
<item name="android:dropDownSelector">#color/background_color_action_bar</item>
</style>
The MyActionBarStyle part works but the MyActionDropDownStyle does not. I suppose that the parent of MyActionDropDownStyle might be wrong. Maybe someone of you has an idea and can help me.
Thanks in advance!
I am wanting to customise the rows of the overflow menu in the action bar. I found a great blog post explaining how to go about doing this, which seem simple enough. The link is below.
http://scriptedpapers.com/2014/08/12/android-action-bar-overflow-menu-customization/
I am specifically wanting to change the background colour of the overflow menu rows so the theme that I am using looks like the following:
<resources>
<!--the theme applied to the application or activity -->
<style name="CustomActionBarTheme" parent="#android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/CustomActionBar</item>
<item name="android:homeAsUpIndicator">#drawable/upcaret</item>
<item name="android:actionOverflowButtonStyle">#style/CustomOverflowButton</item>
<item name="android:popupMenuStyle">#style/PopupMenu</item>
</style>
<!--ActionBar style -->
<style name="CustomActionBar" parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/customBlue</item>
</style>
<style name="CustomOverflowButton" parent="#android:style/Widget.Holo.Light.ActionButton.Overflow">
<item name="android:src">#drawable/overflowbutton</item>
</style>
<style name="PopupMenu" parent="android:Widget.Holo.Light.ListPopupWindow">
<item name="android:popupBackground">#color/customBlue</item>
</style>
Applying this theme to the application, the background colour of the overflow menu remains the same colour as the default for Holo.Light.DarkActionBar, despite setting a custom popupMenuStyle.
For my project, the minSdkVersion is 15 and targetSdkVersion is 19.
Does anyone have any ideas?
Thanks.
Try specifying a 9-patch drawable instead of a color.
Go here and choose the color that you want your rows to be by selecting a color from the "Popup color" drop-down.
The only file you need from the zip is menu_dropdown_panel.9.png.
Make sure to place this file in your various drawable-xxxx folders.
Then use it like this:
<style name="PopupMenu" parent="android:Widget.Holo.Light.ListPopupWindow">
<item name="android:popupBackground">#drawable/menu_dropdown_panel</item>
</style>
If it still doesn't work, add this to the above:
Add this line to your main theme (CustomActionBarTheme):
<item name="android:actionBarWidgetTheme">#style/PopupWrapper</item>
Then add this:
<style name="PopupWrapper" parent="#android:style/Theme.Holo">
<item name="android:popupMenuStyle">#style/PopupMenu</item>
</style>
I want to change the color of the title bar. I tried this:
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:actionBarStyle">#style/ColorBar</item>
</style>
<style name="ColorBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#color/white</item>
<item name="android:textColor">#color/orange</item>
</style>
But it doesn't work. What is wrong in my code shown above?
EDIT : it's the color of the text i want to change, not the background (it's running for the background)
This should work for all devices, you will need the support library (appcompat_v7)
<style name="Theme" parent="#style/BaseTheme"></style>
<style name="BaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="actionBarStyle">#style/ActionBar</item>
<item name="android:actionBarStyle">#style/ActionBar</item>
</style>
<style name="ActionBar" parent="#style/Widget.AppCompat.Light.ActionBar">
<item name="android:background">#color/orange </item>
<item name="background">#color/orange </item>
<item name="android:titleTextStyle">#style/ActionBar.Text</item>
<item name="titleTextStyle">#style/ActionBar.Text</item>
</style>
<style name="ActionBar.Text" parent="#android:style/TextAppearance.Medium">
<item name="android:textColor">#color/orange</item>
</style>
manifest :
android:theme="#style/Theme"
There may be problem with the android version. You should consider old ones and new ones. Try adding these both lines for different versions.
<item name="android:background">#drawable/your_color</item>
<item name="background">#drawable/your_color</item>
Does changing the parent to parent="#android:style/Widget.Holo.Light.ActionBar.Solid" make a difference?
If not, let me know what happens if you move the
<item name="android:actionBarStyle">#style/ColorBar</item> into the AppBaseTheme style
Try setting all of these:
<item name="android:background">#color/something</item>
<item name="android:backgroundStacked">#color/something</item>
<item name="android:backgroundSplit">#color/something</item>
This is an easy way for settings the color of the actionbar-title by Java
getActionBar().setTitle(Html.fromHtml("<font color=\"#ffffff\">" + "TITLE" + "</font>"));
If you're using a support library, then you can use getSupportActionBar();.
I'm new to all of this but I found it easier to go to Res > Value > colors.xml and from there you can change the "primary color." This changed the title bar to the color I selected.
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);
I want to make a Actionbar_style.xml for my app and I would like to use a logo, different than my app logo / icon.
How to change it programmatcially is clear: Change logo that appears in Android ActionBar programatically
But like this I would need to code this into each activity.
Is there a xml tag to define a custom Actionbarlogo in xml already?
my Customstyles.xml
<style name="CustomActionBar0" parent="android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#drawable/action_bg0</item>
</style>
android styles.xml seems not to have it...
<style name="Widget.ActionBar">
<item name="android:background">#android:drawable/action_bar_background</item>
<item name="android:displayOptions">useLogo|showHome|showTitle</item>
<item name="android:divider">#android:drawable/action_bar_divider</item>
<item name="android:height">?android:attr/actionBarSize</item>
<item name="android:paddingLeft">0dip</item>
<item name="android:paddingTop">0dip</item>
<item name="android:paddingRight">0dip</item>
<item name="android:paddingBottom">0dip</item>
<item name="android:titleTextStyle">#android:style/TextAppearance.Widget.ActionBar.Title</item>
<item name="android:subtitleTextStyle">#android:style/TextAppearance.Widget.ActionBar.Subtitle</item>
<item name="android:progressBarStyle">#android:style/Widget.ProgressBar.Horizontal</item>
<item name="android:indeterminateProgressStyle">#android:style/Widget.ProgressBar.Small</item>
<item name="android:homeLayout">#android:layout/action_bar_home</item>
</style>
Just set a value for the android:icon attribute
<style name="AppTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/AppTheme.ActionBarStyle</item>
</style>
<style name="AppTheme.ActionBarStyle" parent="android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#drawable/actionbar_background</item>
<item name="android:titleTextStyle">#style/AppTheme.ActionBar.TitleTextStyle</item>
<item name="android:icon">#drawable/ic_home</item>
<item name="android:indeterminateProgressStyle">#style/IndeterminateProgress</item>
</style>
You don't style the logo in the your style XML, you simply use android:logo in your Manifest, then use setDisplayUseLogoEnabled() to set it in the ActionBar. Here's a project, from Google, that shows you how to switch between the two. http://code.google.com/p/styled-action-bar/
Sounds like you need to use a custom layout for the action bar, that way you can define a whatever you want for logo image.
Action bar / ActionbarSherlock style
<style name="ActionBar" parent="Widget.Sherlock.Light.ActionBar.Solid.Inverse">
<item name="displayOptions">showCustom</item>
<item name="android:displayOptions">showCustom</item>
<item name="customNavigationLayout">#layout/action_bar_home_icon_default</item>
<item name="android:customNavigationLayout">#layout/action_bar_home_icon_default</item>
</style>
#layout/action_bar_home_icon_default is your custom layout, with your custom logo
Yes. You may set different logo for different activities. Here is the sample code in manifest file.
<activity
android:name="MyActivity"
***android:icon="#drawable/logo"***
android:label="#string/app_name"
android:configChanges="orientation"
android:screenOrientation="portrait" />
Hope this help. Cheers!