Currently, I have a split action bar, and there is an edit text near the bottom of the screen.
When I click on the edit text, the keyboard shows up, but the bottom action bar ALSO shows up on top of the keyboard, making it cluttered. Here is what it looks like:
How can I hide only the bottom action bar when I click on edit text?
Here is my code:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
//bottom action bar
getMenuInflater().inflate(R.menu.defaultbottom_tabs, menu);
setActionBar();
return true;
}
// custom layout top action bar
private void setActionBar() {
ActionBar actionBar = getActionBar();
actionBar.setDisplayShowHomeEnabled(false);
// displaying custom ActionBar
View mActionBarView = getLayoutInflater().inflate(R.layout.home_top,null);
actionBar.setCustomView(mActionBarView);
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
}
You can add the android:windowSoftInputMode="adjustPan" attribute to the Activity that shows your EditText. Alternatively, if you really want to do this in code, you can find the split action bar View by using Resources.getIdentifier.
final int id = getResources().getIdentifier("split_action_bar", "id", "android");
final View splitActionBar = findViewById(id);
if (splitActionBar != null) {
// Toggle the visibility
}
Related
I want to achieve 1 of these options for my EditText :
Replace the actionbar that appear on the top by a popup menu instead. Something like this for exemple:
Or make the actionbar floating and child of my current view (in some way same a first option)
i need this because i add my view via windowManager.addView(view, Layout_Params); and in this way i have some trouble with the actionbar on the top (it is displayed blank)
actually i do this to show the actionbar :
#Override
public ActionMode startActionMode(ActionMode.Callback callback) {
Activity host = (Activity) this.getContext();
return host.getWindow().getDecorView().startActionMode(callback);
}
but it's don't work, it's show me an empty white actionbar on the stop instead :( i think i need to create myself the ActionMode but i don't know how to do it.
Ok. You can hide the actionbar when your edittext is gained focus. Then you need to show the popup menu where ever you want.
EditText t = new EditText(this);
t.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View view, boolean b) {
if(b){
getSupportActionBar().hide();
//now show your popup menu at the top position
}else{
getSupportActionBar().show();
//here you dismiss the menu.
}
}
});
In my Android app I want to detect action bar "Sub-Title" click event but I don't know how to do it. I have successfully done Action bar "Title" click as shown in following code---
// Get action bar title ID
final int abTitleId = getResources().getIdentifier("action_bar_title", "id", "android");
//Set OnClick event on action bar title
getActivity().findViewById(abTitleId).setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
// Done
}
});
Referring above code, I have tried to detect action bar "Sub-Title" click event as follows, but there is something wrong and I'm getting "Sub-Title Id" null and it is throwing Null-Pointer Exception.
//Set OnClick event on action bar sub-title
final int abSubTitleId = getResources().getIdentifier("action_bar_sub_title", "id", "android");
getActivity().findViewById(abSubTitleId).setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
}
});
Hope you understand. Thanks..!
The best to handle this scenario is to use custom actionbar view, So create a simple actionbar layout with title textview and subtitle textview and implement respective listener. :)
final ViewGroup actionBarLayout = (ViewGroup) getLayoutInflater().inflate(R.layout.action_bar, null);
// Set up your ActionBar
final ActionBar actionBar = getActionBar();
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setCustomView(actionBarLayout);
// You customization
final int actionBarColor = getResources().getColor(R.color.action_bar);
actionBar.setBackgroundDrawable(new ColorDrawable(actionBarColor));
final TextView actionBarTitle = (TextView) findViewById(R.id.action_bar_title);
final TextView actionBarSubTitle = (TextView) findViewById(R.id.action_bar_sub_title);
The Action Bar subtitle is non clickable as far as i know. Instead you can add the icon there and make it clickable. You can get the click event of icon in onOptionsItemSelected().
I want to write a book-reader application that normally runs in full-screen, but when user touched screen, status bar become visible OVER my main layout without re-creating the whole view.
I already read these but no help at all:
Hide notification bar without using fullscreen
Hide Notification bar
Android Show Activity Title/status bar at the top after it is hidden
any idea how can I do it?
thanks
finally, I did it!!
these 2 methods will show and hide status bar without destroying the layout.
you need to set
private View mMainView; // The main view of the activity
private int mSystemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
then
/** Hides StatusBar and ActionBar */
private void hideSystemUi() {
ActionBar ab = getActionBar();
ab.hide();
// Set flags for hiding status bar
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
// Hide the status bar.
mMainView.setSystemUiVisibility(uiOptions);}
and
/** Shows StatusBar and ActionBar */
private void showSystemUi() {
ActionBar ab = getActionBar();
ab.show();
// Reset flags
mMainView.setSystemUiVisibility(this.mSystemUiVisibility);
}
and put this in your onCreate() method:
mMainView = findViewById(R.id.mainLayout);
mMainView.setSystemUiVisibility(mSystemUiVisibility);
I'm trying put text in to bar, I only put (buttons), I don't know if I can put text 2 lines + image.
Here are references as changing the color:
https://developer.android.com/training/basics/actionbar/styling.html
in this other picture is displayed, as you can put more text in the top bar
http://www.whatsapp.com/img/v3/es/s1-chat.png
Simply create your own view and set it for your ActionBar: setCustomView().
You cannot achieve what you want with the standard layout. For plenty of examples look here:
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActionBar actionBar = getActionBar();
// add the custom view to the action bar
actionBar.setCustomView(R.layout.actionbar_view);
EditText search = (EditText) actionBar.getCustomView().findViewById(R.id.searchfield);
search.setOnEditorActionListener(new OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId,
KeyEvent event) {
Toast.makeText(MainActivity.this, "Search triggered",
Toast.LENGTH_LONG).show();
return false;
}
});
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM
| ActionBar.DISPLAY_SHOW_HOME);
}
}
Source: vogella.com
I don't think you can do it.
I'd advise you just to create a layout that would act like a top bar in your application.
This way you would be able to put there anything you want.
If you have more than one activity that needs to have this top bar, then use fragments instead of activities (to avoid your custom top bar from being animated when new activities are being opened).
In my app, I highlight a check button in the action bar when the user makes a change. I changed the background of the menuitem drawable, but it appears that the button does not expand the entire height of the actionbar (in the image below, what is currently being displayed is on the left; on the right is what I would like the button to look like)
How do I adjust the menuItem button so that its background expands the height of the action bar (and extends to the right edge of the screen)?
This is what I have:
if (myHorizontalLayout.getItemList().size() == 0) {
MenuItem check = menu.findItem(R.id.save);
check.setIcon(R.drawable.check);
} else{
MenuItem check = menu.findItem(R.id.save);
check.setIcon(R.drawable.check_highlight);
}