Android: ActionBar glitch on show and hide - android

I would like to show/hide the action bar upon a click.
It does show and hide but it is not smooth...the bottom part hides but a different background for a little while before disappearing.
I even tried it in a simple hello world app and the result is the same.
Here's the code:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView tv = (TextView) findViewById(R.id.shit);
tv.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
getActionBar().hide();
}
});
}

Use overlay mode instead of showing and hiding the actionbar.
From the actionbar documentation:
Beware that hiding and removing the action bar causes your activity to
re-layout in order to account for the space consumed by the action
bar. If your activity regularly hides and shows the action bar (such
as in the Android Gallery app), you might want to use overlay mode.
Overlay mode draws the action bar on top of your activity layout
rather than in its own area of the screen. This way, your layout
remains fixed when the action bar hides and re-appears. To enable
overlay mode, create a theme for your activity and set
android:windowActionBarOverlay to true. For more information, see the
section about Styling the Action Bar.

Related

Action Bar with custom font and back arrow

I'm trying to customize the font in one activity action bar. I managed to do it by using this code during activity's onCreate:
if(getSupportActionBar()!=null){
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getSupportActionBar().setCustomView(R.layout.secondary_toolbar);
TextView actionBarTitle = getSupportActionBar().getCustomView().findViewById(R.id.toolbar_title);
actionBarTitle.setText(R.string.new_payment_method);
}
The problem is that if I change the toolbar to a custom layout, the code lines which enables the arrow to let the activity to navigate to the previous activity doesn't work anymore. I'm stuck finding a way to modify the font in the action bar and showing the back arrow which allows me to navigate back, at the same time.

How does Android youtube hide the system ui, even when the dialog pops up

I am currently using SystemUiHider for hiding the system status bar and navigation bar.
I came across with a issue that if I want to show a DialogFragment (which actually pops up a dialog), it does break the system ui hiding and show the status bar and navigation bar.
It looks like this
You can see the screen got squashed after the dialog pop up
I thought what I want is the same effect as Youtube Android App
It looks like this
After clicking on the option button on the screen top right, it pops up a dialog looking like this
Which shows the status bar and navigation bar, but it is fine as it doesn't squash the actually video
So can anyone help me out of this? Thanks for any suggestion
I'm currently using SystemUiHider
mUIHider = SystemUiHider.getInstance(this, mContentFrame,
SystemUiHider.FLAG_FULLSCREEN
| SystemUiHider.FLAG_LAYOUT_IN_SCREEN_OLDER_DEVICES
| SystemUiHider.FLAG_HIDE_NAVIGATION
| SystemUiHider.FLAG_HIDE_IMMERSIVE_STICKY);
mUIHider.setup();
mUIHider.hide();
according to android using Immersive view will do. Like in the case below:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
}
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_IMMERSIVE);
}

Contextual Action Bar messing with Toolbar actions

I'm using appcompat v7 and the support design libraries. In my activity there is a regular toolbar, which has three action buttons (RM1, RM2, RM3):
_____________________________________
RM1 RM2 RM3 |
_____________________________________|
And when some items are long-clicked in a list, a contextual action bar (CAB) is shown instead of the regular toolbar. My CAB has a single action (CM).
_____________________________________
CM |
_____________________________________|
When the contextual action bar (CAB) is activated, it hides the regular toolbar. At this point if I click on the contextual menu (CM), everything is ok. But for some reason, if I click over the empty space to the left of CM, the regular menus RM1 and RM2 are shown, despite the regular toolbar being hidden by the CAB. RM1 and RM2 icons are obviously not shown when the CAB is active, but the click handlers are still in place and they are fired even though the regular toolbar is hidden. The CAB is not intercepting the clicks unless it has an action in the clicked point. If I click over CM, it is handled correctly: RM is not shown because that button is exactly below the CM menu.
Is this a bug? Any workaround?
Tested in an Android 4.1 device.
I consider it a bug. I have run into it myself, and isolated it. Here is a workaround, assuming you are extending AppCompatActivity:
#Override
public void onSupportActionModeStarted(ActionMode mode) {
super.onSupportActionModeStarted(mode);
rm1.setEnabled(false);
rm2.setEnabled(false);
rm3.setEnabled(false);
}
#Override
public void onSupportActionModeFinished(ActionMode mode) {
super.onSupportActionModeFinished(mode);
rm1.setEnabled(true);
rm2.setEnabled(true);
rm3.setEnabled(true);
}

Add drop down list to top action bar when split and top bar is from a layout

I have seen a lot of similar questions to mine, but they all seem to differ in some way that makes them not so helpful.
I have a split action bar in my activity. I have customized the top action bar to display my own view since I wanted to add icons to the top and not show the launcher icon or activity title. I have added a menu with icons which appears at the bottom. Here is the code that does both these things:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_basic_fractions);
ActionBar actionBar = getActionBar();
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
View view = View.inflate(this,R.layout.action_bar_top,null);
actionBar.setCustomView(view, new ActionBar.LayoutParams(Gravity.RIGHT | Gravity.CENTER_VERTICAL));;
}
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_basic_fractions, menu);
return true;
}
This code produces the effect I wanted - a split menu with some icon buttons at the top (from the layout view) and some at the bottom (from the menu)
However, I want to add a drop down list to the top action bar. I have found ways to do it if I had a menu there instead of a layout view (for example with submenus or actionLayout), but not with this mixed kind of action bar.
An alternative would be if I could add a menu instead of a layout to be in the top action bar since I am not adding anything special, just a few normal menu buttons, but I couldn't find anyway to force them to appear in the top action bar without making it a layout like this.
Thanks for your help.

Sherlock action bar's menu item background

i am having issue with rendering custom view in Sherlock action bar. what happen is i've successfully set the custom view in action bar designed to set the Title textview in center, but when i set the other menu items like refresh then it's background appears with black color. same things happens with home button. please go through the following snapshot.
as you can see in this image when i set home button visible or set the refresh menu item it should not displayed like this with black background.
in my Activity screen
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menu_activity);
....
View customNav = LayoutInflater.from(this).inflate(R.layout.custom_navigation, null);
TextView textView = (TextView)customNav.findViewById(R.id.screen_title);
textView.setText("Category");
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getSupportActionBar().setCustomView(customNav);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0,Constants.REFRESH_ITEM_ID,0,Constants.LABEL_REFRESH)
.setIcon(R.drawable.ic_refresh)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
return true;
}
I've tried a lot but fail to fix it.Please help me.
Thanks in Advance.
It seems you use Theme.Sherlock.Dark in manifest file for whole application or this activity.
It is normal behavior of ActionBar -- it is defined by style, but your custom view-element has is own backround, text style, etc...
From setCustomView() javadoc:
Custom navigation views appear between the application icon and any action buttons and may use any space available there.
This method just add new view to bar, but doesn't set 'view for whole bar'.
Take a look at http://jgilfelt.github.com/android-actionbarstylegenerator -- this is a style generator for action bar. Pay attention to the toggle button "Style compatibility".
I have found the solution of this not exactly the way i wanted but the other way. actually i've created the images with centred screen title for various screens and setting it as the action bar background rather than creating a custom view and SherlockActionBar is flexible enough to hide the default title displayed on the upper-left corner. all i have done is.
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar()
.setBackgroundDrawable(getResources().getDrawable(R.drawable.menu_head));

Categories

Resources