Skip to content

Commit

Permalink
Improve navdrawer items design
Browse files Browse the repository at this point in the history
- make them rounded (like in the files app)
- add touch states
  • Loading branch information
thgoebel committed Jun 17, 2020
1 parent 0b47381 commit 28107c9
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,13 @@ private void bind(@NonNull NavigationItem item) {
} else {
icon.setVisibility(View.GONE);
}
view.setBackgroundColor(isSelected ? view.getResources().getColor(R.color.bg_highlighted) : Color.TRANSPARENT);
int textColor = isSelected ? mainColor : view.getResources().getColor(R.color.fg_default);

name.setTextColor(textColor);
count.setTextColor(textColor);
icon.setColorFilter(isSelected ? textColor : 0);

view.setSelected(isSelected);
}
}

Expand Down
41 changes: 41 additions & 0 deletions app/src/main/res/drawable-v21/bg_navdrawer_item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?colorControlHighlight">

<item
android:id="@android:id/mask"
android:left="@dimen/spacer_1x"
android:right="@dimen/spacer_1x"
android:top="@dimen/spacer_1hx"
android:bottom="@dimen/spacer_1hx">

<shape android:shape="rectangle">
<!-- value of color is irrelevant, but solid needs to be defined for mask to work -->
<solid android:color="@color/bg_highlighted" />
<corners android:radius="@dimen/spacer_1hx" />
</shape>
</item>

<item
android:left="@dimen/spacer_1x"
android:right="@dimen/spacer_1x"
android:top="@dimen/spacer_1hx"
android:bottom="@dimen/spacer_1hx">

<selector>
<item android:state_selected="true">
<shape android:shape="rectangle">
<corners android:radius="@dimen/spacer_1hx" />
<solid android:color="@color/bg_highlighted" />
</shape>
</item>

<item>
<shape android:shape="rectangle">
<corners android:radius="@dimen/spacer_1hx" />
</shape>
</item>
</selector>
</item>

</ripple>
18 changes: 18 additions & 0 deletions app/src/main/res/drawable/bg_navdrawer_item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:left="@dimen/spacer_1x"
android:right="@dimen/spacer_1x"
android:top="@dimen/spacer_1hx"
android:bottom="@dimen/spacer_1hx">

<item android:state_selected="true">
<shape android:shape="rectangle">
<solid android:color="@color/bg_highlighted" />
</shape>
</item>

<item>
<shape android:shape="rectangle"/>
</item>

</selector>
5 changes: 4 additions & 1 deletion app/src/main/res/layout/item_navigation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg_navdrawer_item"
android:gravity="center_vertical"
android:paddingTop="@dimen/spacer_1hx"
android:paddingBottom="@dimen/spacer_1hx"
android:paddingStart="@dimen/spacer_1x"
android:paddingEnd="@dimen/spacer_1x">
android:paddingEnd="@dimen/spacer_2x">

<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/navigationItemIcon"
Expand Down

0 comments on commit 28107c9

Please sign in to comment.