I am using ActionBar Sherlock library. So, to change the default home button. I did this:
<style name="Theme.mTheme" parent="android:Theme.Sherlock.Light.DarkActionBar">
<item name="android:homeAsUpIndicator">#drawable/custom_home</item>
</style>
which didn't work
So, i added this too:
<item name="homeAsUpIndicator">#drawable/custom_home</item>
now its working. I am having this custom home icon/button on every ActionBar. But in 1 of my Activities i have this in code:
actionBar.setIcon(R.drawable.options_holo_dark);
When i am in that Activity, I can see the icon which i set programatically ie.., options_holo_dark. The 1 which i set in Theme ie.., custom_home is not visible. But the Icon has moved to the Right as if its giving space on the left to the icon i set in theme(though not visible).
This is what i am getting now:
So, how can i avoid that empty space on the left side of the Home Icon?
Thank You
Theme item android:homeAsUpIndicator (and homeAsUpIndicator for ActionBarSherlock) sets drawable for the up icon - that's the little arrow pointing to left that is displayed next to the app icon when you have called setDisplayHomeAsUpEnabled(true) on the action bar.
The size of the up drawable defines the left margin for the app icon (logo). By default its dimensions are 16dp x 16dp. If you put there wider drawable the gap between edge of the screen and the app icon would be wider even though the up icon is not displayed at the moment.
If you want to change the app icon (logo). Use setLogo(int) or setLogo(Drawable) method of ActionBar. Don't forget to call setDisplayUseLogoEnabled(true) too - this method toggles between displaying app icon and custom logo. Also you can define the logo in manifest in attribute android:logo of <application> and <activity> tags and set in theme that you want to use logo instead of app icon in the action bar.
Related
I am trying to custom our home as up indicator on our Android ActionBar. I have change the icon and padding using theme style.
<item name="android:homeAsUpIndicator">#drawable/fb_back</item>
While this make the function
getActionBar().setDisplayHomeAsUpEnabled(false);
become useless. Because in some situation I want to hide the up arrow icon. However calling this leaves large space left of the home button. I am working on sdk 16, so I cannot dynamically set the homeAsUp indicator using
getActionBar().setHomeAsUpIndicator
Some one know a better solution to do this?
I wanted to have up/home arrow button in my activity ActionBar to provide users option for navigating up. In my activity, I have set set getActionBar().setDisplayHomeAsUpEnabled(true); and also have defined parentActiviy in Manifest like this:
<activity
android:name="com.g_node.gca.map.MapActivity"
android:parentActivityName="com.g_node.gca.MainActivity"
android:label="#string/title_activity_map" >
</activity>
It works and I see a left-arrow icon before the icon in ActionBar, that onClick takes back to parentActivity. But I don't see any change in state of actionbar title or icon, when it's clicked/pressed.
How can I style that so when user clicks on that icon, it shows a pressed state? Like in following screenshot:
Moreover, How can I set the padding between the left-arrow icon and the actionbar icon ? In my activity actionbar, both are almost sticked, see screenshot below for reference:
One more thing - I'm setting this icon in my activity pragmatically using getActionBar().setIcon(getResources().getDrawable(R.drawable.icon_maps)); and icon size is 128 x 128.
Thankyou in advance for help.
You can change the background by setting the actionBarItemBackground attribute in your theme. This should be a state-list drawable which reflects states such as pressed and focused.
#android:color/transparent
My actionbar does not use an icon or a title, this makes the click area of the "up" button very small. How can I have a larger click area without a title and icon in the actionbar?
You can put an image where the app icon would be. Just make a transparent image to the width and height for each drawable size you need and put it in the drawable folder, call the image logo (#drawable/logo). You then need to tell the activity to use the logo, it's not hard and these links should help.
http://developer.android.com/guide/topics/ui/actionbar.html
http://developer.android.com/guide/topics/manifest/application-element.html#logo
One way to do it would be to set a custom icon for the "up" button in your app theme as so:
<item name="android:homeAsUpIndicator">#drawable/your_drawable</item>
By default the native ActionBar show app name with app icon on the left. I want to replace all this section
with a custom logo
searching seems that I have to edit the styles.xml file to customize the action bar, but I haven't understood what is the right way and what resolution should have the logo.
"By default, the system uses your application icon in the action bar, as specified by the icon attribute in the <application> or <activity> element. However, if you also specify the logo attribute, then the action bar uses the logo image instead of the icon."
source: http://developer.android.com/guide/topics/ui/actionbar.html
In order to remove the Title of the Activity you call ActionBar.setDisplayShowTitleEnabled(false);
I'm using ActionBarSherlock and have set an icon using android:logo in my theme. I'd like for the icon to be flush with the left side of the screen, but it always has 6px of spacing (measured using the hierarchy viewer). I've highlighted in red the part of the icon that I can't get rid of. If I set DISPLAY_HOME_AS_UP for the action bar, then the up affordance is shown as in the second image with no additional spacing.
I assume the spacing is there to keep the icon in the same place regardless of whether the up arrow present. I'm never going to show the up arrow, so I rather have the icon flush on the left.
You can set customView like this:
actionBar.setCustomView(R.layout.customActionBarLayout)
and create your own layout just as you like it