I'm working on an app which has two activites. The second activity has a back button which provide back navigation.
The problem I have is that the back navigation button takes the background from the toolbar no matter if the toolbar has the "style=" attribute or the "app:theme=".
Here is the toolbar with the "style=" attribute:
http://postimg.org/image/f57zaap4p/
http://postimg.org/image/3u5blxi9l/
An here is the toolbar with the "app:theme=" attribute:
htt.p://postimg.org/image/kkqxgo8d1/
htt.p://postimg.org/image/ofpq5i251/
(Please remove the point from "htt.p" from the last two links - I can't post more than two links)
I want the icons to have a white background. I would appreciate if you can help!
You can style the action overflow button in your styles.xml adding this line:
<item name="android:actionBarItemBackground">...</item>
You can set it as a #drawable or a #color resource. I suggest you to define a selector to manage, e.g, the background color as the icon is pressed.
As for the back arrow, this is, to me, quite an open question. You could take a look at my own question here , where you can also find a selector sample.
Basically you can override the arrow/burger background with
<item name="android:selectableItemBackground">...</item>
but (I fear) it acts as a background for a lot of widgets you might have. In facts, this also overrides actionBarItemBackground, so if you want to use both, the latter is enough.
Related
I do not want to show a menu for only Settings and About, that's why i want the overflow button to open (immediately when clicked) a unified Settings-About page, the same way Instagram does.
At first i thought i might just do a menu with one action that is set to always Shown and has the overflow button icon (the three dots). But there are a lot of icons for different themes and i also think this wouldn't be correct for devices with a menu button.
Follow this:
Go to style, change your theme DarkActionBar to noActionBar.
Add the android design support to your gradle.
Add toolbar to your xml
Add Imageview or imageviewbutton inside your toolbar
Find the three dot image in drawable using image asset
Add your three dot drawable as src of your imageview.
Set oncClick then intent.
I added this translucent gradient background to a Toolbar so buttons are noticeable on any background, but I wonder how to make a shadow just under the button itself instead of what I did?
Thank You
EDIT
So I realized the easiest way to achieve that is by setting a Drawable Resources.
getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_home);
and
<style name="AppTheme" parent="parent_theme">
<item name="actionModeShareDrawable">#drawable/ic_share</item>
</style>
I downloaded Material Vector assets, added shadow in Adobe Illustrator, imported it to PNG. But the Android Studio's Image Asset/Action Bar and Tab Icons mess up with it I didn't get why - it removed the shadow and colors went different even with Custom 'Theme' so I did different dpi image sizes by myself and that's what I got. That's quite what I wanted
http://imgur.com/vnR98H5
Well, I don't know how to do it with simple button, if you could change Button with FloatingActionButton you may use elevation for making a shadow.
Floating Action Button (FAB) is simply a circle button with some drop shadow that unbelieveably could change the world of design. No
surprise why it becomes a signature of Material Design. So let's start
with this thing. Add FAB in layout file with FloatingActionButton and wrap it with FrameLayout since it needs some parent to make it aligned at bottom right position of the screen.
and
The shadow depth is automatically set to the best practices one, 6dp
at idle state and 12dp at pressed state. Anyway you are allowed to
override these values by defining app:elevation for idle state's
shadow depth and app:pressedTranslationZ for press state's.
From: http://inthecheesefactory.com/blog/android-design-support-library-codelab/en
Of course, you can customize by adding your icon. I'm pretty sure, that play icon as you have on button is in Material Design library.
You can also grab it here: https://design.google.com/icons/
To resume, I advice you learn something more about FloatingActionButton, which alows you to add some nice effect like elevation/shadow and others good things from Material library.
Hope it make your development easier and your app more beautiful.
Maybe this is not quite an ActionBar problem but the problem is as follows;
I have an EditText and when you long click on the EditText, text selection options appear on ActionBar's position by default. My problem is that, both the texts and background are white, so they cannot be read. Here is the screenshot:
I tried some possible causes of the problem but nothing helped. For example, I tried to change the theme
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
However, any theme with the AppCompat results totally white.
Also I changed the project theme in Android Studio's interface as follows:
However it's still white.
The copy-paste options are there and you can click on them, but how can I make them appear? Another solution on SA suggested manually replacing gray icons. But I believe this is not the usual case in Android and there should be another way. Any ideas?
Is it possible to change overflow icon in code?
I read this solution: Changing overflow icon in the action bar
But I need to make it in code, to select white or grey style during runtime.
Is it possible?
You can only change this in a theme.
One potential solution would be to call setTheme as the very first thing in onCreate with different themes depending on whether you needed white or gray.
I have a UI sub flow in my application, and I would like to provide forward and back navigation controls on the action bar. Note I said back navigation, not 'up'.
I am aware of the up navigation button feature in Android. In this section of my UI I would like to replace the up button with a back button (and it's icon).
My question is, how do I override the UI of the up button to display a back button instead?
Note I am talking about the UI here. The navigation behavior is easy to achieve.
Have you heard about ActionBarSherlock (ABS)? Reason why I ask is, that ABS is quite close to the native implementation and once you have downloaded that source code you can find out a lot of interesting things. Searching for the home button (in the drawable folders) shows that the icon is named abs__ic_ab_back_holo_light.png.
Searching for that name leads to <homeAsUpIndicator>#drawable/abs__ic_ab_back_holo_light<homeAsUpIndicator> in the Theme.Sherlock.Light. So what does it mean? For ABS you could derive a new theme and overlay the homeAsUpIndicator tag using your own drawable. And how about the native Android scheme? Most likely just the same tag to overwrite. If you don't use ABS derive from a standard theme.
Example: here I have redefined the up indicator (with ABS)
<style name="MyAppStyle" parent="#style/Theme.Sherlock.Light">
<item name="homeAsUpIndicator">#drawable/new_indicator</item>
<item name="android:homeAsUpIndicator">#drawable/new_indicator</item>
Hope that helps! Cheers ....