Skip to content

Commit

Permalink
Merge pull request #4 from nico-gonzalez/bug/bottomview-app-compat-di…
Browse files Browse the repository at this point in the history
…vider

Fix AppCompat bottomNavigationView divider when in tablet mode
  • Loading branch information
Nicolas Gonzalez authored Jan 23, 2017
2 parents d89913b + 453ea83 commit f0ff628
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
1 change: 1 addition & 0 deletions lib/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<dimen name="design_bottom_navigation_width">56dp</dimen>
<dimen name="design_bottom_navigation_elevation">8dp</dimen>
<dimen name="design_bottom_navigation_shadow_height">1dp</dimen>
<dimen name="design_bottom_navigation_shadow_width">1dp</dimen>
<dimen name="design_bottom_navigation_text_size">12sp</dimen>
<dimen name="design_bottom_navigation_active_text_size">14sp</dimen>
<dimen name="design_bottom_navigation_margin">8dp</dimen>
Expand Down
27 changes: 20 additions & 7 deletions lib/src/android/support/design/widget/BottomNavigationView.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public class BottomNavigationView extends FrameLayout {
private MenuInflater mMenuInflater;

private OnNavigationItemSelectedListener mListener;
private boolean mTabletMode;

public BottomNavigationView(Context context) {
this(context, null);
Expand Down Expand Up @@ -159,9 +160,9 @@ public BottomNavigationView(Context context, AttributeSet attrs, int defStyleAtt
mMenuView.setItemBackgroundRes(itemBackground);

if (a.hasValue(R.styleable.BottomNavigationView_tabletMode)) {
boolean tabletMode = a.getBoolean(R.styleable.BottomNavigationView_tabletMode, false);
mTabletMode = a.getBoolean(R.styleable.BottomNavigationView_tabletMode, false);
params.gravity = Gravity.TOP;
mMenuView.setTabletMode(tabletMode);
mMenuView.setTabletMode(mTabletMode);
}

if (a.hasValue(R.styleable.BottomNavigationView_menu)) {
Expand All @@ -171,7 +172,7 @@ public BottomNavigationView(Context context, AttributeSet attrs, int defStyleAtt

addView(mMenuView, params);
if (Build.VERSION.SDK_INT < 21) {
addCompatibilityTopDivider(context);
addCompatibilityDivider(context);
}

mMenu.setCallback(
Expand Down Expand Up @@ -301,14 +302,26 @@ public interface OnNavigationItemSelectedListener {
boolean onNavigationItemSelected(@NonNull MenuItem item);
}

private void addCompatibilityTopDivider(Context context) {
private void addCompatibilityDivider(Context context) {
View divider = new View(context);
divider.setBackgroundColor(
ContextCompat.getColor(context, R.color.design_bottom_navigation_shadow_color));
FrameLayout.LayoutParams dividerParams =
FrameLayout.LayoutParams dividerParams;
if (mTabletMode) {
dividerParams =
new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
getResources().getDimensionPixelSize(R.dimen.design_bottom_navigation_shadow_height));
getResources().getDimensionPixelSize(R.dimen.design_bottom_navigation_shadow_width),
ViewGroup.LayoutParams.MATCH_PARENT
);
dividerParams.gravity = Gravity.END;
} else {
dividerParams =
new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
getResources().getDimensionPixelSize(
R.dimen.design_bottom_navigation_shadow_height
));
}
divider.setLayoutParams(dividerParams);
addView(divider);
}
Expand Down

0 comments on commit f0ff628

Please sign in to comment.