How can I run animation of opening drawer at moment I want?
I used SupportLibrary v7 use "hamburger" animation.
Want to write method like this:
class Activity extends ActionBarActivity{
ToolBar toolbar;
ActionBarDrawerToggle toogle;
...
private void setToolBarIconState(State state) {
if (state == State.menu) {
//flipIconToMenu ?
} else {
//flipIconToBackPointer ?
}
}
to achieve it you need to use canvas.
if you want tutorial then please follwo below link:
https://github.com/neokree/MaterialNavigationDrawer
https://github.com/balysv/material-menu
https://github.com/ikimuhendis/LDrawer
https://github.com/HeinrichReimer/material-drawer
https://github.com/kanytu/android-material-drawer-template
https://github.com/Zlate87/material-navigation-drawer-example
https://github.com/Zlate87/material-navigation-drawer-example
I think that is the default animation from v7 appcompat library
Check this out.
Related
I'm using FancyShowCaseView library. When focusing on a button it work fine, but when focusing on TabLayout or MenuItem of Android SlidingTabs it don't work.
I'm tring to focus on TabLayout or MenuItem's of my app.
listen i have the same problem and add this:
view.getViewTreeObserver().addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
// Layout has happened here.
// Don't forget to remove your listener when you are done with it.
view.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
});
to my code and work fine.
I have 2 questions which can be strange but anyway...
I have toolbar with a title of application. How to change it to picture which is not the logo?
The next question: Is it possible to set, change the size of hamburger icon in toolbar? I made classic navigation drawer with the help of next code below (I used ActionBarDrawerToggle also) but the size is too small if you will compare it with another items(icons) of my toolbar.
toolbar = (Toolbar) findViewById(R.id.application_toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowHomeEnabled(true);
NavigationDrawerFragment drawerFragment = (NavigationDrawerFragment)getFragmentManager().findFragmentById(R.id.fragment_navigation_drawer);
drawerFragment.setUp(R.id.fragment_navigation_drawer,(DrawerLayout)findViewById(R.id.drawer_layout), toolbar );
Thanks for any help! =)
I had solved this problem by this way:
for (int i = 0; i < mToolbar.getChildCount(); i++) {
if(mToolbar.getChildAt(i) instanceof ImageButton){
mToolbar.getChildAt(i).setScaleX(1.5f);
mToolbar.getChildAt(i).setScaleY(1.5f);
}
}
and my hamburger icon size had been increased.
I wanted to increase the size of the Hamburger button and found other answers to not work. Code from this answer worked perfectly and is pasted below.
"Create a custom class which extends the Drawable class to create the
hamburger and navigation icons. There are various methods to change
the size of either but below are the methods which control the
hamburger icon."
public class HamburgerDrawable extends DrawerArrowDrawable {
public HamburgerDrawable(Context context){
super(context);
setColor(context.getResources().getColor(R.color.white));
}
#Override
public void draw(Canvas canvas){
super.draw(canvas);
setBarLength(30.0f);
setBarThickness(5.0f);
setGapSize(5.0f);
}
}
"Then call it from your class:"
private void increaseHamburgerSize(){
mDrawerToggle.setDrawerArrowDrawable(new HamburgerDrawable(this));
}
I have seen in Google's Inbox App, composing a new email, in the toolbar instead of the back button (an arrow) it has a "close" button (see picture).
How can I achieve this?
Use
this.getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_action_close);
to achieve this.
You can create your own close icon or get from material design icon set on GitHub. Also, add this line before above line to make close function as the back arrow.
this.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
You need to define a parent in the manifest, then override onSupportNavigationUp() if using the support app bar of course. Also, go to this handy site for the icon packs: https://www.google.com/design/icons/
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.yourAwesomeLayout);
setupToolBar();
}
private void setupToolBar() {
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
if (toolbar == null) return;
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_close_white_24dp);
}
#Override
public boolean onSupportNavigateUp() {
finish(); // close this activity as oppose to navigating up
return false;
}
sorry for late reply. i found easiest solution for you. here above all answer not works for me (because i want to use toolbar not actionBar due to theming). so try to add close button through xml layout. and it works.
here is an xml syntax to add close button to toolbar(v7) .
app:navigationIcon="#drawable/ic_close_black_24dp"
ans here is an out put image
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle("Search");
toolbar.setNavigationIcon(R.drawable.abc_ic_clear_mtrl_alpha);
setSupportActionBar(toolbar);
An alternative to defining the parent activity in the manifest is to handle what action to take in the onOptionsItemSelected method like in this example:
#Override
public boolean onOptionsItemSelected(MenuItem item){
switch (item.getItemId()) {
// Respond to the action bar's Up/Home/back button
case android.R.id.home:
finish();
break;
}
return super.onOptionsItemSelected(item);
}
You can use this function
fun setNavigationIcon(#DrawableRes resId: Int? = null) {
this.supportActionBar?.apply {
setDisplayHomeAsUpEnabled(true)
setHomeAsUpIndicator(resId ?: R.drawable.ic_close)
}
}
You can define a style:
<style name="Theme.Toolbar.Clear">
<item name="toolbarNavigationIcon">#drawable/abc_ic_clear_mtrl_alpha</item>
</style>
and use it in your theme:
<style name="Theme.Clear">
<item name="toolbarTheme">#style/Theme.Toolbar.Clear</item>
</style>
I would like to dynamically change the "home" icon in the ActionBar. This is easily done in v14 with ActionBar.setIcon(...), but I can't find anyway to accomplish this in previous versions.
If your actionbar works like Sherlock and is based on menu items, this is my solution:
#Override
public boolean onPrepareOptionsMenu(Menu menu) {
MenuItem switchButton = menu.findItem(R.id.SwitchSearchOption);
if(searchScriptDisplayed){
switchButton.setIcon(R.drawable.menu_precedent);
}else{
switchButton.setIcon(R.drawable.icon_search);
}
return super.onPrepareOptionsMenu(menu);
}
If you are using the ActionbarCompat code provided by google, you can access the home icon via the ActionBarHelperBase.java class for API v4 onwards.
//code snippet from ActionBarHelperBase.java
...
private void setupActionBar() {
final ViewGroup actionBarCompat = getActionBarCompat();
if (actionBarCompat == null) {
return;
}
LinearLayout.LayoutParams springLayoutParams = new LinearLayout.LayoutParams(
0, ViewGroup.LayoutParams.MATCH_PARENT);
springLayoutParams.weight = 1;
// Add Home button
SimpleMenu tempMenu = new SimpleMenu(mActivity);
SimpleMenuItem homeItem = new SimpleMenuItem(tempMenu,
android.R.id.home, 0, mActivity.getString(R.string.app_name));
homeItem.setIcon(R.drawable.ic_home_ftn);
addActionItemCompatFromMenuItem(homeItem);
// Add title text
TextView titleText = new TextView(mActivity, null,
R.attr.actionbarCompatTitleStyle);
titleText.setLayoutParams(springLayoutParams);
titleText.setText(mActivity.getTitle());
actionBarCompat.addView(titleText);
}
...
You should be able to modify the code to the home button accessible to the activities that extend ActionBarActivity and change it that way.
Honeycomb seems a little harder and it doesn't seem to give such easy access. At a guess, its id should also be android.R.id.home so you may be able to pull that from the view in ActionBarHelperHoneycomb.java
I would say you do something like this :
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_menu_drawer);
see the link How to change the icon actionBarCompat
The ActionBar will use the android:logo attribute of your manifest, if one is provided. That lets you use separate drawable resources for the icon (Launcher) and the logo (ActionBar, among other things).
I use greendroid to implement to actionbar under api 11.
Now i have a strange behaviour in my MainView (the startview works well)
public class MainView extends GDActivity {
private boolean ison = false;
private FinderThread finder;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
//this.getActionBar().removeViewAt(0);
setActionBarContentView(R.layout.mainlayout);
getActionBar().setBackgroundColor(Color.parseColor("#bf27c3"));
setTitle("TEST");
setTitleColor(Color.WHITE);
addActionBarItem(getActionBar().newActionBarItem(NormalActionBarItem.class).setDrawable(R.drawable.person));
Looking:
The Actionbar text is empty and no home button. please help
You can try to set the Title and the Color of the Title with
getActionBar().setTitle("Title")
The same for the color. Try also to set the color via an RGB value.
I can't promise that this will work, because i don't use greendroid for my actionbars. But i understand that you don't use actionbarsherlock + greendroid because they are only compatible with a trick (a bit hacking xD)