how to hide/unhide the actionbar list on android 3? - android

i am using android 3.0 actionbar with a dropdown and a searchWidget.
I would like to hide the dropdown when the user expands the search and unhide the dropdown when the user closes the search.
Here is a picture to explain bettere
and here is the code i use to make the dropdown
ActionBar bar = this.getActionBar();
bar.setTitle(this.getString(R.string.app_name));
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
...
ListDittaListener listener = new ListDittaListener(this);
bar.setListNavigationCallbacks( seleziona_ditta, listener);

Thanks to this https://stackoverflow.com/a/6454288/579646
searchView.setOnSearchClickListener( new OnClickListener() {
#Override
public void onClick(View v) {
Log.v(MyApp.TAG, "search view On Search Click");
ActionBar bar = FattureActivity.this.getActionBar();
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
}
});
searchView.setOnCloseListener( new OnCloseListener() {
#Override
public boolean onClose() {
Log.v(MyApp.TAG, "search view On Close");
ActionBar bar = FattureActivity.this.getActionBar();
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
return false;
}
});

Related

HomeAsUpIndicator Custom View

I'm looking at adding a custom view for the HomeAsUpIndicator whenever there are new message. I want to bring attention to the hamburger icon when there are new messages, and then use the default hamburger icon when there aren't new messages.
I have two functions to display custom icon and display default, but I want to use a custom View.
protected void setCustomIcon() {
getSupportActionBar().setDefaultDisplayHomeAsUpEnabled(false);
mDrawerToggle.setDrawerIndicatorEnabled(false);
mDrawerToggle.setHomeAsUpIndicator(R.drawable.ic_menu_hamburger);
mDrawerToggle.setToolbarNavigationClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mDrawerLayout.openDrawer(mDrawerList);
}
});
}
protected void setDefaultIcon() {
mDrawerToggle.setDrawerIndicatorEnabled(true);
}
Is there a way to use a custom View instead of a resId or a drawable?

Close floating action button Android

I used the following library https://github.com/futuresimple/android-floating-action-button and everything works fine.
How do I close the menu automatically after clicking on one of the buttons on the same menu?
Its open-source lib, You can read the source code and find that by your self.
FloatingActionsMenu.collapse(); // close the menu
FloatingActionsMenu.toggle(); // toggle the menu
FloatingActionsMenu.expand(); // open the mneu
In the Click listener of the Menu Item call .collapse()
FloatingActionMenu fAM = (FloatingActionMenu) findViewById(R.id.fAM_ID);
FloatingActionButton fAB1 = (FloatingActionButton)findViewById(R.id.fAB_ID);
floatingActionButton1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//Action
Toast.makeText(MainActivity.this, "FAB Click", Toast.LENGTH_SHORT).show();
fAM.collapse();
}
});

How to detect Action bar "Sub-Title" click event in Android Fragment..?

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().

searchview loases focus on orientation change

I am using searchview in my app with action bar and fragments. searchview is opened in the portrate mode and when we change the orientation it closes. If there is any text present in searchview it will not close on orientation chnage. I want to retain the state of searchview on orientation change even if the searchview is empty.How can i do this?i tried
setRetainInstance(true);
But it is not working. Please help me.
I implemented it myself since Android does not seem to save it for me.
final String s = savedSearchString;
if (s != null) {
searchViewMenuItem.expandActionView(); // opens the action view
}
searchView.post(new Runnable() {
#Override
public void run() {
searchView.setQuery(s, false); // sets the last search string on the view
}
});
'savedSearchString' is coming from the savedInstanceState. Make sure you set the initial conent of the search window on "" and not on null (default), otherwise it won't re-open an empty window.
You can create a boolean.
And when you open the searchView, you put boolean to true.
When you close the searchView, yout put boolean false.
In the onCreate, if the boolean = true, open the searchView.
final SearchView searchView = (SearchView) itemSearch.getActionView();
searchView.setQueryHint(Html
.fromHtml("<font color = #ffffff>Search...</font>"));
searchView.setOnSearchClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
//your code
}
});

Hide only bottom action bar Android

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
}

Categories

Resources