Created
October 28, 2014 08:08
-
-
Save dodgex/7bc81fd2cbb70a8d5117 to your computer and use it in GitHub Desktop.
splitActionBar for Android 5.0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<here.is.my.SplitToolbar | |
android:id="@+id/toolbar" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_alignParentBottom="true"/> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public boolean onCreateOptionsMenu(Menu menu) { | |
if (toolbar == null) { | |
EnhancedMenuInflater.inflate(getMenuInflater(), menu, false); | |
} | |
return super.onCreateOptionsMenu(menu); | |
} | |
// somewhere after views have been set. | |
if (toolbar != null) { | |
EnhancedMenuInflater.inflate(getMenuInflater(), toolbar.getMenu(), true); | |
toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() { | |
@Override | |
public boolean onMenuItemClick(MenuItem item) { | |
return onOptionsItemSelected(item); | |
} | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.Context; | |
import android.support.v7.widget.ActionMenuView; | |
import android.support.v7.widget.Toolbar; | |
import android.util.AttributeSet; | |
import android.view.View; | |
import android.view.ViewGroup; | |
public class SplitToolbar extends Toolbar { | |
public SplitToolbar(Context context) { | |
super(context); | |
} | |
public SplitToolbar(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
} | |
public SplitToolbar(Context context, AttributeSet attrs, int defStyleAttr) { | |
super(context, attrs, defStyleAttr); | |
} | |
@Override | |
public void addView(View child, ViewGroup.LayoutParams params) { | |
if (child instanceof ActionMenuView) { | |
params.width = LayoutParams.MATCH_PARENT; | |
} | |
super.addView(child, params); | |
} | |
} |
2 items case: items are aligned to screen sides(not taking half of the width as expected)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
android:layout_alignParentBottom
is specific to RelativeLayoutParams. But thanks for saving me some time of coding 👍