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
Related
Building a simple app with an overflow menu. The overflow menu shows up fine, however the actual MenutItems are not visible. Theme is current set to Theme.MaterialComponents.Light.NoActionBar.
But when I switch the theme to Theme.MaterialComponents.NoActionBar, it works just fine:
Here is the menu.xml:
<menu xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:android="http://schemas.android.com/apk/res/android">
<!-- TODO Step 9.1 - Add an item for the settings fragment -->
<item android:id="#+id/settings_dest"
android:icon="#drawable/ic_settings"
android:menuCategory="secondary"
android:title="#string/settings"
android:visible="true"
android:enabled="true"
app:showAsAction="never|withText"/>
<item android:id="#+id/settings_second"
android:icon="#drawable/ic_settings"
android:menuCategory="secondary"
android:title="Second"
android:visible="true" android:enabled="true" android:checkable="true"/>
<!-- TODO END STEP 9.1 -->
</menu>
And the style.xml:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.NoActionBar">
<!-- 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/colorBlack</item>
</style>
Any suggestions?
Try addung your parent theme like this:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar.Bridge">
</style>
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>
I have a dummy app that I'm making just to get the hang of Android development. I managed to get a menu overflow icon to appear on my toolbar, but I can't seem to figure out how to change it to white.
I'm using a Toolbar widget (without support libraries; that's something I don't want to do).
Here is what I have:
I just want to make the overflow menu white.
styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="android:Theme.Material.Light.DarkActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:colorPrimary">#color/primary</item>
<item name="android:colorPrimaryDark">#color/primary_dark</item>
<item name="android:colorAccent">#color/accent</item>
</style>
You want to change android:textColorSecondary like so:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="android:Theme.Material.Light.DarkActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:colorPrimary">#color/primary</item>
<item name="android:colorPrimaryDark">#color/primary_dark</item>
<item name="android:colorAccent">#color/accent</item>
<!-- Here you go. This changes overflow icon colour. -->
<item name="android:textColorSecondary">#color/WHITE</item>
</style>
Just add android:theme="#style/ThemeOverlay.AppCompat.Dark" to the toolbar
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay"
android:theme="#style/ThemeOverlay.AppCompat.Dark"/>
This thing worked for me :)
<style name="AppThemeLL" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
<item name="android:colorBackground">#color/white</item>
<item name="android:textColorSecondary">#color/white</item>
</style>
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>
I'm trying to make an appcompat theme but the color isn't working, and the icon won't show either... maybe im missing something. Here is my xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<color name="background_test">#410000</color>
<color name="font_general">#ffffff</color>
<style name="MyTheme"
parent="#style/Theme.AppCompat">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<style name="AudioFileInfoOverlayText">
<item name="android:paddingLeft">2dp</item>
<item name="android:paddingBottom">2dp</item>
<item name="android:textColor">#ffffffff</item>
<item name="android:textSize">18sp</item>
<item name="android:shadowColor">#000000</item>
<item name="android:shadowDx">1</item>
<item name="android:shadowDy">1</item>
<item name="android:shadowRadius">1</item>
</style>
<!-- general styles for the action bar -->
<style name="MyActionBar"
parent="#style/Widget.AppCompat.Light.ActionBar.Solid">
<item name="android:icon">#drawable/ic_launcher</item>
<item name="icon">#drawable/ic_launcher</item>
<item name="background">#color/background_test</item>
<item name="android:background">#color/background_test</item>
</style>
</resources>
What should i add to make it work?
EDIT:
It won't work with a toolbar either... After i set:
Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
setSupportActionBar(toolbar);
It will lose all the user defined theme and will only get the parent theme... Here are my xmls (Yes i have a lot of redundant/test values as i wanted to try everything)
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/my_awesome_toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
background="?attr/colorPrimary"
app:popupTheme="#style/MyActionBarStyle"
android:background="?attr/colorPrimary"
app:theme="#style/MyActionBarStyle"
/>
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android">
<!-- the theme applied to the application or activity -->
<color name="background_test">#410000</color>
<color name="font_general">#ffffff</color>
<!-- general styles for the action bar -->
<style name="CustomActionBarTheme" parent="#style/Theme.AppCompat.Light.NoActionBar">
<item name="actionBarStyle">#style/MyActionBarStyle</item>
<item name="android:panelColorBackground">#color/background_test</item>
<item name="android:headerBackground">#color/background_test</item>
<item name="android:colorBackground">#color/background_test</item>
<item name="android:backgroundSplit">#color/background_test</item>
<item name="backgroundSplit">#color/background_test</item>
<item name="colorAccent">#color/background_test</item>
<!-- Here we setting appcompat’s actionBarStyle -->
<!-- ...and here we setting appcompat’s color theming attrs -->
<item name="colorPrimary">#color/background_test</item>
<item name="colorPrimaryDark">#color/background_test</item>
</style>
<style name="MyActionBarStyle">
<item name="colorAccent">#color/background_test</item>
<!-- Here we setting appcompat’s actionBarStyle -->
<item name="android:panelColorBackground">#color/background_test</item>
<item name="android:headerBackground">#color/background_test</item>
<item name="android:colorBackground">#color/background_test</item>
<item name="android:backgroundSplit">#color/background_test</item>
<item name="backgroundSplit">#color/background_test</item>
<!-- ...and here we setting appcompat’s color theming attrs -->
<item name="colorPrimary">#color/background_test</item>
<item name="colorPrimaryDark">#color/background_test</item>
<item name="android:background">#color/background_test</item>
<item name="background">#color/background_test</item>
</style>
<style name="AudioFileInfoOverlayText">
<item name="android:paddingLeft">2dp</item>
<item name="android:paddingBottom">2dp</item>
<item name="android:textColor">#ffffffff</item>
<item name="android:textSize">18sp</item>
<item name="android:shadowColor">#000000</item>
<item name="android:shadowDx">1</item>
<item name="android:shadowDy">1</item>
<item name="android:shadowRadius">1</item>
</style>
</resources>
Screenshot:
http://i.imgur.com/4iohVwP.png
New EDIT:
It won't work from the code either...
Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
setSupportActionBar(toolbar);
ActionBar test=getSupportActionBar();
test.setLogo(R.drawable.ic_launcher); //this is the only one working...
test.setBackgroundDrawable(new ColorDrawable(0x410000));
test.setDisplayShowTitleEnabled(false);
test.setDisplayShowTitleEnabled(true);
EDIT:
There are some bugs reported for the new Appcompat-v7, this is probably a bug:
http://code.google.com/p/android/issues/detail?id=77763&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars
If you are using Toolbar then your actionBarStyle is not used.
You need to style Toolbar directly:
<android.support.v7.widget.Toolbar
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="..."
android:background="..."
app:theme="#style/ThemeOverlay.AppCompat.ActionBar"
app:titleTextAppearance="..."
app:subtitleTextAppearance="..." />
There are more attributes you can customize, these are just examples.
I'm not sure why getSupportActionBar().setBackgroundDrawable(...) doesn't work for you, I've just tried it in various places and it works fine.
It is an example:
<style name="Theme.MyTheme" parent="Theme.AppCompat.Light">
<!-- colorPrimary is used for the default action bar background -->
<item name="colorPrimary">#color/my_color</item>
<!-- colorPrimaryDark is used for the status bar -->
<item name="colorPrimaryDark">#color/my_darker_color</item>
<!-- colorAccent is used as the default value for colorControlActivated
which is used to tint widgets -->
<item name="colorAccent">#color/accent</item>
<!-- appcompat’s actionBarStyle -->
<item name="actionBarStyle">#style/MyActionBarStyle</item>
</style>
Also I suggest you using the new Toolbar.
You can find more info here:
https://chris.banes.me/2014/10/17/appcompat-v21/
One solution to get the AppCompatActivity to use the primary theme color on the Action Bar for all api levels is to declare the colors in the same theme like this:
<style name="Theme.Custom" parent="Theme.AppCompat">
<!--API < 21 -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="colorButtonNormal">#color/colorButtonNormal</item>
<!-- 21 < API this is probably not needed, included for illustration -->
<item name="android:colorPrimary" tools:ignore="NewApi">#color/colorPrimary</item>
<item name="android:colorPrimaryDark" tools:ignore="NewApi">#color/colorPrimaryDark</item>
<item name="android:colorAccent" tools:ignore="NewApi">#color/colorAccent</item>
<item name="android:colorButtonNormal" tools:ignore="NewApi">#color/colorButtonNormal</item>
</style>
note: remember to remove the theme declared in values-v21 for this to work