mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-24 21:50:30 +00:00
Updated toolbar to look more android-like
This commit is contained in:
parent
57a9b5bc0c
commit
4820a6e01c
@ -1,7 +1,9 @@
|
||||
package com.topjohnwu.magisk.redesign
|
||||
|
||||
import android.graphics.Insets
|
||||
import android.os.Bundle
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.ncapdevi.fragnav.FragNavController
|
||||
import com.topjohnwu.magisk.R
|
||||
import com.topjohnwu.magisk.databinding.ActivityMainMd2Binding
|
||||
import com.topjohnwu.magisk.redesign.compat.CompatActivity
|
||||
@ -20,8 +22,39 @@ open class MainActivity : CompatActivity<MainViewModel, ActivityMainMd2Binding>(
|
||||
HomeFragment::class
|
||||
)
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
setSupportActionBar(binding.mainToolbar)
|
||||
}
|
||||
|
||||
override fun onTabTransaction(fragment: Fragment?, index: Int) {
|
||||
super.onTabTransaction(fragment, index)
|
||||
|
||||
setDisplayHomeAsUpEnabled(false)
|
||||
}
|
||||
|
||||
override fun onFragmentTransaction(
|
||||
fragment: Fragment?,
|
||||
transactionType: FragNavController.TransactionType
|
||||
) {
|
||||
super.onFragmentTransaction(fragment, transactionType)
|
||||
|
||||
when (transactionType) {
|
||||
FragNavController.TransactionType.PUSH -> setDisplayHomeAsUpEnabled(true)
|
||||
else -> Unit //dunno might be useful
|
||||
}
|
||||
}
|
||||
|
||||
override fun peekSystemWindowInsets(insets: Insets) {
|
||||
viewModel.insets.value = insets
|
||||
}
|
||||
|
||||
fun setDisplayHomeAsUpEnabled(isEnabled: Boolean) {
|
||||
when {
|
||||
isEnabled -> binding.mainToolbar.setNavigationIcon(R.drawable.ic_back_md2)
|
||||
else -> binding.mainToolbar.navigationIcon = null
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -13,4 +13,10 @@ class HomeFragment : CompatFragment<HomeViewModel, FragmentHomeMd2Binding>() {
|
||||
|
||||
override fun consumeSystemWindowInsets(insets: Insets) = insets
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
|
||||
activity.title = "Home"
|
||||
}
|
||||
|
||||
}
|
@ -2,8 +2,6 @@
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
|
||||
<corners android:radius="2.5dp" />
|
||||
|
||||
<gradient
|
||||
android:angle="135"
|
||||
android:endColor="?colorSecondary"
|
||||
|
9
app/src/main/res/drawable/ic_back_md2.xml
Normal file
9
app/src/main/res/drawable/ic_back_md2.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="?colorOnSurface"
|
||||
android:pathData="M20,11H6.83l2.88,-2.88c0.39,-0.39 0.39,-1.02 0,-1.41 -0.39,-0.39 -1.02,-0.39 -1.41,0L3.71,11.3c-0.39,0.39 -0.39,1.02 0,1.41L8.3,17.3c0.39,0.39 1.02,0.39 1.41,0 0.39,-0.39 0.39,-1.02 0,-1.41L6.83,13H20c0.55,0 1,-0.45 1,-1s-0.45,-1 -1,-1z" />
|
||||
</vector>
|
@ -24,39 +24,22 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?colorSurfaceVariant"
|
||||
android:paddingTop="@{viewModel.insets.top}">
|
||||
android:paddingTop="@{viewModel.insets.top}"
|
||||
tools:paddingTop="24dp">
|
||||
|
||||
<com.google.android.material.appbar.MaterialToolbar
|
||||
android:id="@+id/main_toolbar"
|
||||
style="?styleToolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@android:color/transparent"
|
||||
app:contentInsetStartWithNavigation="0dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
tools:paddingTop="24dp">
|
||||
tools:title="Home" />
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="@dimen/l1">
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
style="?styleToolbarTitle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:text="Home" />
|
||||
|
||||
<View
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="5dp"
|
||||
android:layout_gravity="center|bottom"
|
||||
android:background="@drawable/bg_accent" />
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
</com.google.android.material.appbar.MaterialToolbar>
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="3dp"
|
||||
android:layout_gravity="start|bottom"
|
||||
android:background="@drawable/bg_accent" />
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
|
@ -14,7 +14,6 @@
|
||||
|
||||
<!--Toolbar-->
|
||||
<attr name="styleToolbar" format="reference" />
|
||||
<attr name="styleToolbarTitle" format="reference" />
|
||||
|
||||
<!--Card-->
|
||||
<attr name="styleCardNormal" format="reference" />
|
||||
|
@ -9,9 +9,11 @@
|
||||
<style name="Foundation.Compat" />
|
||||
|
||||
<!--region Do not remove-->
|
||||
<style name="WidgetFoundation" />
|
||||
<style name="WidgetFoundation" parent="android:Widget" />
|
||||
|
||||
<style name="AppearanceFoundation" />
|
||||
<style name="AppearanceFoundation">
|
||||
<item name="android:fontFamily">@font/exo</item>
|
||||
</style>
|
||||
<!--endregion-->
|
||||
|
||||
<style name="Foundation.Base" parent="Foundation.Compat">
|
||||
@ -25,7 +27,6 @@
|
||||
<item name="styleAppbar">@style/WidgetFoundation.Appbar</item>
|
||||
|
||||
<item name="styleToolbar">@style/WidgetFoundation.Toolbar</item>
|
||||
<item name="styleToolbarTitle">@style/WidgetFoundation.Toolbar.Title</item>
|
||||
|
||||
<item name="styleCardNormal">@style/WidgetFoundation.Card</item>
|
||||
<item name="styleCardOnPrimary">@style/WidgetFoundation.Card.OnPrimary</item>
|
||||
|
@ -13,23 +13,14 @@ variant. Make sure to use style referenced by attribute defined it attrs.xml.
|
||||
</style>
|
||||
|
||||
<style name="WidgetFoundation.Toolbar" parent="Widget.MaterialComponents.Toolbar.Surface">
|
||||
<item name="contentInsetStart">0dp</item>
|
||||
<item name="contentInsetLeft">0dp</item>
|
||||
<item name="contentInsetRight">0dp</item>
|
||||
<item name="contentInsetEnd">0dp</item>
|
||||
<item name="titleTextAppearance">?appearanceTextTitleNormal</item>
|
||||
<item name="titleTextColor">?colorOnSurface</item>
|
||||
<item name="subtitleTextAppearance">?appearanceTextCaptionNormal</item>
|
||||
<item name="subtitleTextColor">?colorOnSurfaceVariant</item>
|
||||
<item name="android:background">@android:color/transparent</item>
|
||||
<item name="contentInsetStartWithNavigation">0dp</item>
|
||||
</style>
|
||||
|
||||
<style name="WidgetFoundation.Toolbar.Title" parent="Widget.MaterialComponents.TextView">
|
||||
<item name="android:layout_width">match_parent</item>
|
||||
<item name="android:layout_height">?attr/actionBarSize</item>
|
||||
<item name="android:textAppearance">?appearanceTextTitleNormal</item>
|
||||
<item name="android:gravity">start</item>
|
||||
<item name="android:layout_gravity">center</item>
|
||||
<item name="android:lines">1</item>
|
||||
<item name="android:padding">@dimen/l1</item>
|
||||
</style>
|
||||
|
||||
|
||||
<style name="WidgetFoundation.Card" parent="Widget.MaterialComponents.CardView">
|
||||
<item name="cardBackgroundColor">?attr/colorSurface</item>
|
||||
|
Loading…
x
Reference in New Issue
Block a user