Menu Resource Item Position Title to Left of Icon - android

Is there a way to position the title text for a menu item to the left of the icon rather than to the right in an ActionBar? So in:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/forward"
android:title="Begin"
android:icon="#drawable/ForwardArrow"
android:showAsAction="always"></item>
</menu>
It would appear "Begin ->" instead of "-> Begin"

While you can define things like android:actionButtonStyle in a theme and apply that to your activity, I am not aware that you can use that to turn around and affect the positioning of the image versus the text.
However, you can use android:actionLayout in your <item> element to replace the stock action button with something else of your own design. If you putter around the Android source and find where these action buttons come from, I suspect that you will find that they are styled Button objects using the compound drawable stuff to put an image alongside the text caption. Cloning that and switching the side for the image, then using that for your actionLayout, should work, at least in theory.

Related

How to set text on bottom of logo actionbar android

enter image description here
How to i print text on bottom of Action bar logo
<item android:title="Customer Inquiry"
android:id="#+id/customer_inquiry"
app:showAsAction="always|withText"
android:icon="#drawable/customer_inqury"/>
i set text but its not visible...!
there is no such option for MenuItem, by design these items don't and shouldn't have any text. if you really need those labels you need to write own drawing class and use app:actionLayout or even whole custom Toolbar set for Activity with setSupportActionBar(..) in Activity

Removing icon from BottomNavigationView

I want my menu items on the BottomNavigationBar to have text-only labels with no icon. Unfortunately, it looks like design_bottom_navigation_item.xml always has a 24x24dp space reserved for the icon, with no publicly-exposed way to set it to gone. And even after getting past that, the label layout is set to a layout_gravity of bottom|center_horizontal, and it doesn't look like there's a way to programatically set layout_gravity to centered.
What is the fastest, easiest way to achieve the goal of a text-only menu item on the bottom nav bar? I'm thinking I can do this by creating a custom version of the item layout, then subclassing BottomNavigationItemView, BottomNavigationMenuView, and BottomNavigationView to specify that custom layout... but that seems like an awful lot of work for one little change. Am I missing something simpler?
dont put iandroid:icon property to your item
Just use the code below. I tried hard to do this easy way but failed.Then I made an alternative. Just use transparent color instead of icon drawble
<item
android:icon="#android:color/transparent"
android:id="#+id/navigation_id"
android:title="title" />
Add this in your dimens file. Then you can add padding according to your navigation view size.
<dimen name="design_bottom_navigation_height"tools:override="true">30dp</dimen>

Image "inside" button while keeping standard animations

I would like to define a button in Android, through XML, which, below the standard Button graphics (change color when clicked, slightly rounded edges,...), shows an image of my choice. I would like the final product to be somewhat like this:
I have tried change the src and background of an ImageButton, but it does not provide the intended effect. Could you please point me some way of achieving this?
Maybe that's not exactly what you mean by standard, but when you set a background, you end up having to recreate the behavior when the button is clicked. The best way to do it in Android is by using a selector as your button's background. Create a XML drawable with the selector in it.
Example:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="#drawable/button_bg_pressed" />
<item android:drawable="#drawable/button_bg_default" />
</selector>
That way, when your button is clicked, it will change the background to other image that does what you want.
EDIT:
There are other modifiers such as focused, if you need.
If you want Lollipop's ripple effects, I think you can create a Layout and put your button inside it. Change the Layout background and set the button background to transparent. If that doesn't work, try adding android:background="?android:attr/selectableItemBackground" to your button.
As Paulo said, you can achieve the click effect with a selector.
See this answer (https://stackoverflow.com/a/30192562) it gives the code for a very nice and customizable ripple effect.

where is the attribute android:titleCondensed applicable in menu

Can anybody please explain me about this? I couldn't find sufficient information in developer documentation.
Is it also applicable when item is shown as action and long clicked on icon shows a toast containing title.
In short: it shows up when space is nice to be kept.
I took pictures on Galaxy S4 4.4.2.
The first picture is a landscape, having only three selection related icons, you can see that the condensed title is used there:
however if I don't supply the the titleCondensed it uses title and it clearly fits:
The full title is used at any other places where space is not an issue, like the "tooltip" (long press on an action bar icon, internally called cheat sheet) or the overflow menu:
... and here's part of code I used (with appcompat-v7):
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<!-- Possibly more items like "Edit Item" and "Delete Item" below -->
<item android:id="#+id/action_select_all"
android:icon="#drawable/ic_action_select_all"
android:title="Select All"
android:titleCondensed="All"
app:showAsAction="ifRoom|withText" />
<!-- Same for Select None <-> None -->
<!-- Same for Invert Selection <-> Invert -->
</menu>
All of the above is empirical observation, and hence probably incomplete, but I was curious, so here are the Android code points implementing the below:
Note the internal package and these are from the framework not the support library!
MenuItemImpl.getTitleForItemView returns the title based on prefersCondensedTitle, which has three implementations:
Action Bar icon and text: ActionMenuItemView: true
Action Bar overflow probably: ListMenuItemView: false
Old style Options Menu: IconMenuItemView: true
http://developer.android.com/guide/topics/resources/menu-resource.html
Simply put, the titleCondensed is the title you would like to show when the title string is too long for the device it's being showed on.

How to change the shape of an onClick highlight?

I currently have icons in a GridView on my app. When they are clicked, an orange square appears around them briefly as a highlight. The only problem is that I think this looks amateurish and would like to change the shape so that it clips the icon in the GridView instead of a large square. If you are unsure as to what I mean, it is carried out successfully in the Catch Notes app, on their dashboard/home screen. I was just wondering whether anybody knew a way to tackle this or if it is simply a small layout attribute.
https://play.google.com/store/apps/details?id=com.threebanana.notes&hl=en
Thanks in advance, all help would be appreciated!
It looks effectively like this EditText in the image below. The way that it borders the EditText in orange is exactly how it borders the icons in the home screen when clicked.
First, in your layout file, specify a drawable background:
android:background="#drawable/bg_your_view"
Then edit the bg_your_view file which is in drawable:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="#drawable/bg_your_view_pressed" android:state_pressed="true"></item>
<item android:drawable="#drawable/bg_your_view_normal" android:state_focused="false"></item>
</selector>
At last, create corresponding drawable files for pressed and normal states:
bg_your_view_pressed.xml contains the shape, the color you want for highlight.
bg_your_view_normal.xml is similar, just without highlight effect.
I've decided that the easiest way to solve this problem is to simply reference another image when the image on the GridView has been clicked. This means that the second image can just be edited in Photoshop in order to have a glow around it.

Categories

Resources