feat: 首页侧栏

This commit is contained in:
HuanCheng65 2022-04-10 11:15:16 +08:00
parent 7172cf3e6e
commit e2578b6a28
4 changed files with 36 additions and 16 deletions

View File

@ -15,7 +15,7 @@ import android.widget.TextView
import android.widget.Toast
import androidx.viewpager.widget.ViewPager.OnPageChangeListener
import butterknife.BindView
import com.google.android.material.bottomnavigation.BottomNavigationItemView
import com.google.android.material.navigation.NavigationBarItemView
import com.google.android.material.navigation.NavigationBarMenuView
import com.google.android.material.navigation.NavigationBarView
import com.google.android.material.snackbar.Snackbar
@ -106,12 +106,13 @@ open class MainActivity : BaseActivity(), NavigationBarView.OnItemSelectedListen
return false
}
@SuppressLint("RestrictedApi")
private fun findView() {
menuView = navigationView.getChildAt(0) as NavigationBarMenuView
menuView = navigationView.menuView as NavigationBarMenuView
}
protected fun initView() {
val hideExploreItemView = menuView!!.getChildAt(msgNavPosition) as BottomNavigationItemView
val hideExploreItemView = menuView!!.getChildAt(msgNavPosition) as NavigationBarItemView
val badge = layoutInflater.inflate(R.layout.layout_badge, hideExploreItemView, true)
badgeTextView = badge.findViewById(R.id.tv_msg_count)
if (hideExplore) {

View File

@ -1,11 +1,13 @@
package com.huanchengfly.tieba.post.widgets.theme;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.google.android.material.navigationrail.NavigationRailView;
import com.huanchengfly.tieba.post.R;
import com.huanchengfly.tieba.post.ui.theme.interfaces.Tintable;
@ -22,24 +24,27 @@ public class TintNavigationRailView extends NavigationRailView implements Tintab
}
public TintNavigationRailView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
this(context, attrs, R.attr.navigationRailStyle);
}
@SuppressLint("CustomViewStyleable")
public TintNavigationRailView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
this(context, attrs, defStyleAttr, R.style.Widget_MaterialComponents_NavigationRailView);
}
public TintNavigationRailView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
if (isInEditMode()) {
return;
}
if (attrs == null) {
mBackgroundTintResId = R.color.transparent;
mBackgroundTintResId = 0;
mItemIconTintResId = 0;
mItemTextTintResId = 0;
applyTintColor();
return;
}
TypedArray array = getContext().obtainStyledAttributes(attrs, R.styleable.TintNavigationRailView, defStyleAttr, 0);
mBackgroundTintResId = array.getResourceId(R.styleable.TintNavigationRailView_backgroundTint, R.color.transparent);
mBackgroundTintResId = array.getResourceId(R.styleable.TintNavigationRailView_backgroundTint, 0);
mItemIconTintResId = array.getResourceId(R.styleable.TintNavigationRailView_itemIconTintList, 0);
mItemTextTintResId = array.getResourceId(R.styleable.TintNavigationRailView_itemTextTintList, 0);
array.recycle();

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<com.huanchengfly.tieba.post.widgets.theme.TintCoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
<com.huanchengfly.tieba.post.widgets.theme.TintConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/background"
@ -10,17 +10,25 @@
<com.huanchengfly.tieba.post.widgets.theme.TintNavigationRailView
android:id="@+id/navbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:bottomNavigationBackgroundTint="@color/default_color_nav"
android:layout_width="wrap_content"
android:layout_height="0dp"
app:backgroundTint="@color/default_color_nav"
app:headerLayout="@layout/header_main_nav_rail"
app:elevation="4dp"
app:itemIconTintList="@color/bottom_item_icon_tint_list"
app:itemTextTintList="@color/bottom_item_icon_tint_list"
app:labelVisibilityMode="unlabeled"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:menu="@menu/navbar_main" />
<com.huanchengfly.tieba.post.widgets.MyViewPager
android:id="@+id/mViewPager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</com.huanchengfly.tieba.post.widgets.theme.TintCoordinatorLayout>
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/navbar"
app:layout_constraintTop_toTopOf="parent" />
</com.huanchengfly.tieba.post.widgets.theme.TintConstraintLayout>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="@dimen/size_avatar_normal"
android:layout_height="@dimen/size_avatar_normal"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:srcCompat="@mipmap/ic_launcher_foreground" />