Android: Change icon of action share item on Action Bar - android

I understand that this question has been asked here many times but after of spending hours searching for the solution I am unable to find one.
My requirement simple, I just want to change share icon on Action Bar to white color. I've the white drawables and using built-in Action Bar.
have tried setting icon in menu xml but didn't work. Any help would be appreciated.
<item
android:id="#+id/action_share"
android:actionProviderClass="android.widget.ShareActionProvider"
android:showAsAction="ifRoom"
android:icon="#drawable/ic_action_share_white"
android:title="#string/action_share"/>

Take a look at the ShareActionProvider's onCreateActionView() method:
public View onCreateActionView() {
// Create the view and set its data model.
...
// Lookup and set the expand action icon.
TypedValue outTypedValue = new TypedValue();
mContext.getTheme().resolveAttribute(R.attr.actionModeShareDrawable, outTypedValue, true);
Drawable drawable = mContext.getResources().getDrawable(outTypedValue.resourceId);
...
So, to change this image, it looks like you should change the value of actionModeShareDrawable for your app's theme. Unfortunately this attribute seems not to be public in the framework (though it is if using AppCompat or ActionBarSherlock).
If you are using neither of these libraries, a possible solution is to create a subclass of ShareActionProvider and reimplement the onCreateActionView() method (though you'll have to duplicate its code and, possibly, the resources it uses).

Related

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>

Status bar wrong colour initially and pushing layout off screen slightly

I am working with an activity that has a few different stages. It is designed like a wizard so a few sections of it are tutorial like pages where I hide the toolbar and status bar. The Activity starts off with the toolbar hidden. In each of the fragments, I have an onToolbarShown(ActionBar ab) (called in the base fragments onStart() method) which I use to edit the title, if the back button shows etc, and then I call the showToolbar method below:
public void showSystemUi(boolean show){
if(show){
KKDeviceUtil.showSystemUI(mRootLayout);
}else {
KKDeviceUtil.hideSystemUI(mRootLayout);
}
}
#Override
public void showToolbar(boolean show){
if(getSupportActionBar() != null){
showSystemUi(show);
if(show) {
mRootLayout.setFitsSystemWindows(true);
getSupportActionBar().show();
}else{
getSupportActionBar().hide();
mRootLayout.setFitsSystemWindows(false);
}
}
}
(showSystemUi is the stock show/hide method suggested by android here)
The problem is that the first time I show the toolbar, the status bar is the wrong colour and the layout is shunted down by the height of the status bar. As seen here:
When I next switch fragments, the problem clears up:
And if I go back to the previous fragment, it looks correct:
I don't get this problem if I never hide the toolbar/system windows in the first place. I originally had some of the operations in a different order and thought that re-arranging them could help, but It didn't seem to make any difference. I also tried calling setStatusBarColor but that had no effect. I also have <item name="android:statusBarColor">#color/status_bar_color</item> in my v21/styles.xml which is the correct colour for my status bar, and my primaryDark is the same colour as the screenshot (buggy) above shows.
I can't seem to find what I am doing wrong here, is this the correct way to show/hide my toolbar/system ui and why does this only happen on the first showing of the toolbar?
(Note: it is hard to see from the screenshots, but in the first screenshot, the 'Done' button is much closer to the bottom than the correct placing in the third screenshot)
Please see below i've shown you demo style that will reflect color on the status bar.
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/side_bar_color</item>
<item name="colorPrimaryDark">#color/side_bar_color</item>
<item name="colorAccent">#color/side_bar_color</item>
</style>
There "colorPrimaryDark" is that color which will used at status bar, you need to set this style to your application or activity at manifest class

Android actionbar icons always in overflow

I declared my menu items with android:showAsAction="ifRoom". My Activity is extending ActionBarActivity. In preview it is as expected but when run on my phone is it always in overflow.
From what I've seen nothing else is needed. My phone runs in Android 4.4.2 KitKat.
Am I missing anything else?
You have to define your own namespace, if you want to use the showAsAction attribute with ActionBarCompat(I assume you are using ActionBarCompat because you mentioned, that you're extending ActionBarActivity):
xmlns:app="http://schemas.android.com/apk/res-auto"
and use showAsAction like this:
<item [...] app:showAsAction="always"></item>
Just try this...
<item android:id="#+id/action_blah"
android:icon="#drawable/ic_c"
android:title="#string/action_blah"
app:showAsAction="(yourOptions)"/>
(yourOptions):
always = To force to show on the actionbar.
never = Not to show on your actionbar ever.
and
ifRoom = It will let your item if there is enough space on your action bar.
You can see these in Landscape mode.
HappyCoding

change the background of actionbar from java code as defined in the style.xml

i have set the theme as:
<application
........
android:theme="#style/Theme.Example" >
.......
.......
</application>
i have several fragment in one activity. in one of my fragment i have change the color of actionbar as:
((MainActivity)getActivity()).getSupportActionBar()
.setBackgroundDrawable(new ColorDrawable(bitmap1.getPixel(0, 0)));
this works fine. now, i want to change the actionbar as it defined in #style/Theme.Example while i am traveling to another fragment.
after googling for several times, i find out only how to change the color or backround drawable of actionbar. not how to get back to the default actionbar style as it is defined in the style.xml
any help or link would be too much helpful :) thank you.
if it is needed, i can provide the style.xml. i have created them from this actionbar style generator tool
oh my god, i have found the answer in 5 min after posting the questions. i have used this:
Drawable d = getResources().getDrawable(R.drawable.ab_background_textured_example);
((MainActivity)getActivity()).getSupportActionBar().setBackgroundDrawable(d);
if you are asking that what the hell is R.drawable.ab_background_textured_example is, then you need to read my question properly and check out the link. on that page i have downloaded the zip file which contains the graphics. in the res/drawable there is a xml which is named ab_background_textured_example. and this is the default background of my actionbar. cheer.
if anyone need know more about it, just comment bellow.

Menu Resource Item Position Title to Left of Icon

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.

Categories

Resources