I would like to do an edit mode, in the style of the tablet gmail app.
If the user presses the edit button on the actionbar, than I would like to show him/her an action view, that has a done button on the left side, and a delete button on the right.
I have an example that works without actionbarsherlock here:
https://code.google.com/p/romannurik-code/source/browse/misc/donediscard
I would like to stick to actionbarsherlock, for compatibility reasons.
This is the way I solved it in onCreateOptionsMenu:
getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.white));
getSupportActionBar().setIcon(R.drawable.white);
for (int i = 0; i < menu.size(); i++) {
menu.getItem(i).setVisible(false); }
getSupportActionBar().setDisplayHomeAsUpEnabled(false); does nothing, so I had to set the home icon to a white 1x1 pixel drawable.
I also had to set the background color of the actionbar, as the actionview's background color. If I had not, than the 1x1 home icon would have padding around it, and the original background color would be visible around the white home button.
Anyone got a better solution for this?
edit:
I also had to change the style:
<style name="Theme.Styled" parent="Theme.Sherlock.Light">
<item name="android:homeAsUpIndicator">#drawable/white</item>
<item name="homeAsUpIndicator">#drawable/white</item>
</style>
Also..settings android:homeAsUpIndicator increased my min api level from 8 to 11 which is also an issue.
If you're on API level 14 or above and are not using ActionbarSherlock, this code in onCreateOptionsMenu will disable the up button, remove the left caret, and remove the icon:
ActionBar actionBar = getActionBar();
if (actionBar != null) {
actionBar.setHomeButtonEnabled(false); // disable the button
actionBar.setDisplayHomeAsUpEnabled(false); // remove the left caret
actionBar.setDisplayShowHomeEnabled(false); // remove the icon
}
You were almost there. To hide the icon/logo completely, use setDisplayShowHomeEnabled(false). The call you're using just removes the little arrow that indicates that the icon acts as an "up" button also.
This worked for me, though its a slight change in the above mentioned solution
android.support.v7.app.ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setHomeButtonEnabled(false); // disable the button
actionBar.setDisplayHomeAsUpEnabled(false); // remove the left caret
actionBar.setDisplayShowHomeEnabled(false); // remove the icon
}
Though it's an older post, I would like to share an answer which worked for me.
To hide the UP button in actionbar, use the following in OnCreateOptionsMenu:
if (getSupportActionBar() !=
getSupportActionBar().hide();
}
To remove the UP button in actionbar, use the following in OnCreateOptionsMenu:
if (getSupportActionBar() !=
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
}
I hope it will help newbies.
Related
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
as you can see in the picture below, the white space lays between status bar and actionbar. I normally include android.support.v7.widget.Toolbar with TextView and then I set supportActionbar in MainActivity.
This bug happens only on Sony phone with android 6.0
Try this code
ActionBar actionBar = getActionBar();
if(actionBar !=null)
{
actionBar.hide();
}
I don’t know what the real name of this is, but I want to change the top menu for an image or button. Someone can tell me what the name is and how do that in my android aplication?.
something like it!!!
in your menu xml add this in the item tag android:icon="#drawable/youricon"
app:showAsAction="always"
If you mean the custom text, you can add custom vews in your toolbar. The toolbar is just a viewgroup where you can add views inside. See this as an example.
If you mean to add a custom image instead of the back arrow, you can switch it with the toolbar.setNavigationIcon(Drawable drawable) method.
If you want to display the default arrow, then try with this (after setting the toolbar).
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}
i want to know how can i hide system bar under when i click on a spinner because i have 2 spinner and when i click on them they show me the system bar but i dont want to see it so someone can tell me how can i do to hide it when i click on a spinner button please ?
final ActionBar action = getActionBar();
civilite = (Spinner) findViewById(R.id.civilite);
date_naissance = (Spinner) findViewById(R.id.date_naissance);
nom = (EditText) findViewById(R.id.nom);
prenom = (EditText) findViewById(R.id.prenom);
email = (EditText) findViewById(R.id.email);
civilite.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
getWindow().getDecorView().setSystemUiVisibility(View.GONE);
action.hide();
}
});
I guess this has to do with how you configure ActionBar and the order of calls. While not really an answer to your problem, I post here how I do in my App to show / hide it:
First of all, I declare in the styles.xml, in the Theme for the Activity, the settings so ActionBar will be Overlaid your application window. This allows you to use 100% of the screen height, and the actionbar, if present, will be rendered over your content:
<style name="Nebular.ActionBar" parent="#android:style/Theme.Holo">
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowActionModeOverlay">true</item>
</style>
Either add those <item> to your existing theme, or add the whole <style> in styles.xml then declare in the Manifest that your activity uses it:
<activity
android:name="blahblah"
.
.
android:theme="#style/Nebular.ActionBar" >
Now you shouldn't have any problem at all to hide or show the actionbar:
action.hide() will hide the actionbar (action is from your code)
action.show() will show it.
I don't know if it's possible to hide & show the actionbar if it's not in overlay mode. Your attempt to switch to full screen should do the trick, but mind that any touch when in fullscreen causes to exit fullscreen mode.
I want to remove the left arrow from the action bar and only icon and title needed.
My code:
getSupportActionBar().setIcon(R.drawable.logo);
getSupportActionBar().setDisplayShowTitleEnabled(true);
getSupportActionBar().setTitle(R.string.dashboardtitle);
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
But this doesn't remove the left arrow . Any help!!
According to specification android specification:
To enable the icon for up navigation (which displays the "up" indicator next to the icon), call setDisplayHomeAsUpEnabled(true) on your ActionBar:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
...
}
So you should set actionBar.setDisplayHomeAsUpEnabled(false);
UPDATE:
I test next code with ActionBar sherlock and it's work. There is no back arrow:
getSupportActionBar().setIcon(R.drawable.ic_launcher);
getSupportActionBar().setDisplayShowTitleEnabled(true);
getSupportActionBar().setTitle(R.string.about_event_location);
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
You need to add this to your actionBar theme. You can replace arrow image with your own image which can be transparent
<item name="android:homeAsUpIndicator">#drawable/action_arrow</item>
getActionBar().setHomeAsUpIndicator(R.drawable.action_arrow);
Where action_arrow is a 25x10px transparent png.
Same code for sherlock would be:
getSupportActionBar().setHomeAsUpIndicator(R.drawable.action_arrow);
#vivek: works great. I do not recommend to use #android:color/transparent as Tim Cooper said, because the Title is aligned to the left. So a empty image is better
In AndroidManifest.xml
remove the below code, which will remove back button from your ActionBar
android:parentActivityName=".Main.MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".Main.MainActivity" />
Just keep it like below:
<activity
android:name=".YourActivity"
android:label="#string/your_activity_label">
</activity>