pref: 首页 Snackbar 不再遮挡底栏

This commit is contained in:
HuanChengFly 2021-02-12 13:27:38 +08:00
parent b15e61799e
commit 1185ae7061
2 changed files with 13 additions and 42 deletions

View File

@ -16,7 +16,6 @@ import android.util.Log
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.widget.FrameLayout
import android.widget.TextView
import android.widget.Toast
import androidx.viewpager.widget.ViewPager.OnPageChangeListener
@ -46,14 +45,10 @@ import com.huanchengfly.tieba.post.models.MyInfoBean
import com.huanchengfly.tieba.post.services.NotifyJobService
import com.huanchengfly.tieba.post.utils.*
import com.huanchengfly.tieba.post.widgets.MyViewPager
import com.huanchengfly.tieba.post.widgets.theme.TintToolbar
open class MainActivity : BaseActivity(), BottomNavigationView.OnNavigationItemSelectedListener, OnNavigationItemReselectedListener {
var mAdapter: ViewPagerAdapter = ViewPagerAdapter(supportFragmentManager)
@BindView(R.id.toolbar)
lateinit var mToolbar: TintToolbar
@BindView(R.id.mViewPager)
lateinit var mViewPager: MyViewPager
@ -68,9 +63,6 @@ open class MainActivity : BaseActivity(), BottomNavigationView.OnNavigationItemS
private val newMessageReceiver: BroadcastReceiver = NewMessageReceiver()
private val accountSwitchReceiver: BroadcastReceiver = AccountSwitchReceiver()
@BindView(R.id.appbar)
lateinit var appbar: FrameLayout
public override fun onResume() {
val reason = ThemeUtil.getSharedPreferences(this).getString(ThemeUtil.SP_SWITCH_REASON, null)
val followSystemNight = appPreferences.followSystemNight
@ -131,7 +123,6 @@ open class MainActivity : BaseActivity(), BottomNavigationView.OnNavigationItemS
val hideExploreItemView = menuView!!.getChildAt(if (hideExplore) 1 else 2) as BottomNavigationItemView
val badge = layoutInflater.inflate(R.layout.layout_badge, hideExploreItemView, true)
badgeTextView = badge.findViewById(R.id.tv_msg_count)
setSupportActionBar(mToolbar)
if (hideExplore) {
mBottomNavigationView.menu.removeItem(R.id.navbar_explore)
}
@ -156,9 +147,7 @@ open class MainActivity : BaseActivity(), BottomNavigationView.OnNavigationItemS
@SuppressLint("RestrictedApi")
override fun onPageSelected(position: Int) {
val baseFragment = mAdapter.getItem(position)
appbar.visibility = if (baseFragment.hasOwnAppbar()) View.GONE else View.VISIBLE
mBottomNavigationView.menu.getItem(position).isChecked = true
mToolbar.title = mBottomNavigationView.menu.getItem(position).title
if (position == (if (hideExplore) 1 else 2)) {
badgeTextView!!.visibility = View.GONE
}
@ -166,7 +155,6 @@ open class MainActivity : BaseActivity(), BottomNavigationView.OnNavigationItemS
override fun onPageScrollStateChanged(state: Int) {}
})
appbar.visibility = if (mAdapter.getItem(0).hasOwnAppbar()) View.GONE else View.VISIBLE
}
@SuppressLint("ApplySharedPref")
@ -392,10 +380,6 @@ open class MainActivity : BaseActivity(), BottomNavigationView.OnNavigationItemS
}
}
override fun setTitle(newTitle: String?) {
mToolbar.title = newTitle
}
private inner class NewMessageReceiver : BroadcastReceiver() {
@SuppressLint("RestrictedApi")
override fun onReceive(context: Context, intent: Intent) {

View File

@ -1,39 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<com.huanchengfly.tieba.post.widgets.theme.TintRelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<com.huanchengfly.tieba.post.widgets.theme.TintLinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:backgroundTint="@color/default_color_window_background"
android:id="@+id/background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".activities.MainActivity">
<FrameLayout
android:id="@+id/appbar"
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.huanchengfly.tieba.post.widgets.theme.TintToolbar
app:popupTheme="?attr/actionOverflowMenuStyle"
app:navigationIcon="@null"
app:toolbarBackgroundTint="@color/default_color_toolbar"
app:itemTint="@color/default_color_toolbar_item"
app:secondaryItemTint="@color/default_color_toolbar_item_secondary"
app:activeItemTint="@color/default_color_toolbar_item_active"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:title="@string/title_main"
app:titleTextAppearance="@style/Toolbar.Title"
app:subtitleTextAppearance="@style/Toolbar.Subtitle" />
</FrameLayout>
android:layout_height="0dp"
android:layout_weight="1">
<com.huanchengfly.tieba.post.widgets.MyViewPager
android:layout_above="@id/navbar"
android:layout_below="@id/appbar"
android:id="@+id/mViewPager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.huanchengfly.tieba.post.widgets.MyViewPager
android:layout_above="@id/navbar"
android:layout_below="@id/appbar"
android:id="@+id/mViewPager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<com.huanchengfly.tieba.post.widgets.theme.TintBottomNavigationView
android:id="@+id/navbar"
@ -47,4 +34,4 @@
app:labelVisibilityMode="unlabeled"
app:menu="@menu/navbar_main" />
</com.huanchengfly.tieba.post.widgets.theme.TintRelativeLayout>
</com.huanchengfly.tieba.post.widgets.theme.TintLinearLayout>