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.
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
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);
}
There's a way to know the color of hold event on action bar? Like image below:
The theme is Theme.AppCompat.Light
I just want the color value... but, how?
you can achieve it by using custom action bar.
Add in onCreate methode:
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setDisplayShowTitleEnabled(false);
// create xml in layout and inflate into view.
View v = getLayoutInflator().inflate(R.layout.search, null);
// here you can find id add listener on add button.
Button addBtn = (Button)v.findViewById(R.id.addBtn);
addBtn.setonClickListener(this);
//Now add view in your action bar.
actionBar.setCustomView(v);
I think it will help.
This color is defined in xml file. you can create your own style by using:
actionbar style generator
or you can see the source code of
Theme.AppCompat
in summary this value is set statically and you can find it without needing to get it at the runtime because it is what you have styled.
for other part of your app you can create theme with
android holo colors
if you want the color value here it is:
The color is
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.
I know that I can make the ActionBar overlay using requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY)
and can toggle/show the status bar in my screen (by switching between FLAG_FULLSCREEN and FLAG_FORCE_NOT_FULLSCREEN).
This works great. However, I don't want my layout moving when I toggle the status bar.
I know that I can make the status bar "overlay" (albeit not transparently) the content using:
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
This works also great, except for the (expected) consequence that, when using an ActionBar, the ActionBar gets half cut off - half of it is under the status bar basically.
So I am wondering, is there a way to "move the ActionBar down" by the status bar's height in this case?
I know that in worse case, I can do this with a custom view that lives within the layout, but I rather not do this (want to benefit from the ActionBar).
thanks!
so apparently, you can do this in Jellybean. google includes two examples in the api docs. here is a link: http://developer.android.com/reference/android/view/View.html#setSystemUiVisibility%28int%29
summary:
use setSystemUiVisibility on a view to toggle visibility (on jellybean+).
It's not perfect, but this is how I have achieved what you want:
In onCreate:
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
Then:
private void hideStatusBar() {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
}
private void showStatusBar() {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
I also have a style on the activity with the following:
<style name="readingStyle" parent="#style/Theme.Sherlock">
<item name="android:windowActionBarOverlay">true</item>
<item name="windowActionBarOverlay">true</item>
</style>
Your activity will shift down when the status bar shows, but I don't think it's too noticeable.
Why you dont make it in the Manifest
android:theme="#android:style/Theme.Black.NoTitleBar"
than you have no statusbar and more space for the Actionbar??
Put this method in onCreate() method activity:
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
refer: link