I have a menu.xml file:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".StudentMarks" >
<item android:id="#+id/action_example"
android:title="#string/action_example"
android:showAsAction="withText|ifRoom"
style="#style/SelectedYear" />
<item android:id="#+id/action_settings"
android:title="#string/action_settings"
android:orderInCategory="100"
android:showAsAction="never" />
</menu>
The item action example has a title that represents the current year (2014).
I can see it in the action bar but i don't know how can I set the size of the year.
I would like to make it bigger.
my styles.xml files
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
<style name="SelectedYear" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:textSize">16sp</item>
</style>
</resources>
use this attribute in xml
android:textAppearance="?android:attr/textAppearanceLarge"
Try change your styles.xml
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:textSize">20sp</item>
</style>
Related
I want to change the color of my app name, search icon and overflow menu in the appbar to white. I used textColorPrimary but its not working, it is all black.
Here is my code
colors.xml
<resources>
<color name="colorPrimary">#9C27B0</color>
<color name="colorPrimaryDark">#CE93D8</color>
<color name="textColorPrimary">#FFFFFF</color>
<color name="windowBackground">#FFFFFF</color>
<color name="navigationBarColor">#FFFFFF</color>
<color name="colorAccent">#FF80AB</color>
</resource>
styles.xml
<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="textColorPrimary">#color/textColorPrimary</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
AndroidManifest.xml
<activity
android:name=".MainActivity"
android:theme="#style/AppTheme"
android:label="#string/title_activity_welcome">
</activity>
menumain.xml
<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=".MainActivity">
<item
android:id="#+id/action_search"
android:icon="#drawable/ic_search"
android:orderInCategory="100"
android:title="#string/action_search"
app:showAsAction="always" />
<item
android:id="#+id/action_settings"
android:title="#string/action_settings"
android:orderInCategory="100"
app:showAsAction="never" />
</menu>
This is what I want - A white text(app name), search icon(fixed,i used a white search icon so no problem) and white overflow menu
Below theme will work
<style name="ToolbarThemeWhite" parent="#style/ThemeOverlay.AppCompat.ActionBar">
<item name="colorControlNormal">#color/white</item>
<item name="android:textColorPrimary">#color/white</item>
</style>
Use like
<android.support.v7.widget.Toolbar
...
app:theme="#style/ToolbarThemeWhite"
...
/>
Create this style and set to Toolbar:
<style name="AppTheme.Toolbar" parent="ThemeOverlay.AppCompat.ActionBar">
<!-- Customize color of navigation drawer icon and back arrow -->
<item name="colorControlNormal">#color/textColorPrimary</item>
</style>
<style name="AppTheme.Toolbar.Title" parent="TextAppearance.Widget.AppCompat.Toolbar.Title">
<!-- Set proper title size -->
<item name="android:textSize">#dimen/abc_text_size_title_material_toolbar</item>
<!-- Set title color -->
<item name="android:textColor">#color/textColorPrimary</item>
</style>
Toolbar code:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:background="#color/toolbar_bg"
app:theme="#style/AppTheme.Toolbar"
app:titleTextAppearance="#style/AppTheme.Toolbar.Title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"/>
Add these lines in your style:
<style name="TextAppearance" parent="TextAppearance.AppCompat.Widget.ActionBar.Menu">
<item name="android:textColor">#color/white</item>
</style>
FIXED...Strangely it was rendering with black but when I run on a real device it was white.!!
been trying to change the color of the menu items that appear on the Toolbar.
Here is my menu xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/action_settings"
android:title="Settings"
app:showAsAction="never"
android:orderInCategory="100"/>
<item android:id="#+id/always"
android:title="Always"
app:showAsAction="always"
android:orderInCategory="101"/>
<item android:id="#+id/never"
android:title="Never"
app:showAsAction="never"
android:orderInCategory="102"/>
<item android:id="#+id/ifroom"
android:title="If Room"
android:orderInCategory="103"
app:showAsAction="ifRoom"/>
<item android:id="#+id/always1"
android:title="Always1"
app:showAsAction="always"
android:orderInCategory="104"/>
</menu>
styles.xml
<resources>
<!-- 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>
<item name="actionMenuTextColor">#color/white</item>
<item name="android:actionMenuTextColor">#color/white</item>
</style>
</resources>
I've tried using the style options but I cannot figure out how to change the color. The actionMenuTextColor & android:actionMenuTextColor do not solve the problem. It still appears black. Which looks untidy on my blue background.
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
android:background="#color/colorPrimary">
</android.support.v7.widget.Toolbar>
Turns out I was inheriting the wrong theme! This works for me!
Remove this line in styles.xml
<item name="actionMenuTextColor">#color/white</item>
<item name="android:actionMenuTextColor">#color/white</item>
and add this
<item name="android:textColor">#color/red</item>
<item name="android:itemBackground">#color/skyBlue</item>
Complete code :
<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>
<item name="android:textColor">#color/red</item>
<item name="android:itemBackground">#color/skyBlue</item>
</style>
How can i set four icons(Bookmarks,search,menu,locationdrop) in ActionBar like a image ?
Is it possible through action bar or not ? or tell me any other option .
menu_main.xml
<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.comida.MainActivity">
<item
android:id="#+id/action_settings"
android:orderInCategory="100"
android:title="#string/action_settings"
app:showAsAction="never" />
</menu>
style.xml
<resources xmlns:tools="http://schemas.android.com/tools">
<style name="AppTheme" parent="#android:style/Theme.Holo.Light">
<item name ="android:actionBarStyle">#style/CustomActionBar</item>
</style>
<!-- Application theme. -->
<style name="CustomActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#f26925</item>
<item name="android:logo">#android:color/transparent</item>
<item name="android:titleTextStyle">#style/CustomTextColor</item>
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:windowNoTitle">true</item> <!-- Hides the Action Bar -->
<item name="android:windowFullscreen">true</item> <!-- Hides the status bar -->
</style>
<style name="CustomTextColor" parent="#android:style/TextAppearance" >
<item name="android:textColor">#0000ff</item>
</style>
</resources>
It is coming like this image using this .
You can use a Toolbar from android.support.v7.widget.Toolbar. It's support custom layout in it.
https://developer.android.com/reference/android/support/v7/widget/Toolbar.html
https://guides.codepath.com/android/Using-the-App-ToolBar
This is my menu.xml at the moment
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/action_save"
android:title="Save"
android:icon="#drawable/ic_action_save"
app:showAsAction="ifRoom|withText" />
<item
android:id="#+id/action_delete"
android:title="Delete This"
android:icon="#drawable/ic_action_delete"
app:showAsAction="never"/>
</menu>
However, the spacing between the overflow menu and the main Save button is pretty small. I'd like to add more spacing.
Here is my styles.xml
<resources>
<style name="MyTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- ... -->
<item name="android:actionButtonStyle">#style/MyActionButtonStyle</item>
</style>
<style name="MyActionButtonStyle" parent="Widget.AppCompat.Light.ActionButton">
<item name="android:paddingEnd">100dip</item>
<item name="android:paddingRight">100dip</item>
<item name="android:layout_marginRight">100dip</item>
<item name="android:horizontalSpacing">100dip</item>
</style>
<!-- ... -->
</resources>
Unfortunately, that style has no effect.
The only thing I can get to work is <item name="android:minWidth">300dp</item>. I am using this for now, but the problem is I am going to have various buttons of different widths, so it would be much better if I could set spacing or padding instead of min-width.
Why are all of my padding rules of 100dip not working, and what should I do instead?
Found solution, added following lines in styles.xml file and it worked!!
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:actionButtonStyle">#style/MyActionButtonStyle</item>
</style>
<style name="MyActionButtonStyle" parent="AppBaseTheme">
<item name="android:minWidth">20dip</item>
<item name="android:padding">0dip</item>
</style>
In the ApplicationManifest I have:
<application android:theme="#style/AppTheme" >
And as a style I have:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
<style name="FullscreenTheme" parent="android:Theme.NoTitleBar">
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowBackground">#null</item>
<item name="metaButtonBarStyle">#style/ButtonBar</item>
<item name="metaButtonBarButtonStyle">#style/ButtonBarButton</item>
</style>
<!-- Backward-compatible version of ?android:attr/buttonBarStyle -->
<style name="ButtonBar">
<item name="android:paddingLeft">2dp</item>
<item name="android:paddingTop">5dp</item>
<item name="android:paddingRight">2dp</item>
<item name="android:paddingBottom">0dp</item>
<item name="android:background">#android:drawable/bottom_bar</item>
</style>
<!-- Backward-compatible version of ?android:attr/buttonBarButtonStyle -->
<style name="ButtonBarButton" />
</resources>
In preview mode, the Actionbar can be seen. However, on my device it is not. What am I missing?
Try to change parent theme of "AppTheme" to another one, i.e. "Theme.Holo.Light".
Actually actionbar is there but the menus are not visible
modify your res->menu-> main.xml
<item
android:id="#+id/action_settings"
android:orderInCategory="100"
android:title="#string/action_settings"/>
like this
remove line
android:showAsAction="never"
My god...
In my case there was two styles.xml - in feature and installed.. both should be the same