浏览代码

引入TitileBar;优化显示效果;调整页面显示内容

Frankensteinly 9 月之前
父节点
当前提交
308586fe9d

+ 39 - 0
app/src/main/java/com/grkj/iscs_mc/view/widget/TitleBar.kt

@@ -0,0 +1,39 @@
+package com.grkj.iscs_mc.view.widget
+
+import android.content.Context
+import android.util.AttributeSet
+import android.view.View
+import android.widget.RelativeLayout
+import com.grkj.iscs_mc.R
+import com.grkj.iscs_mc.databinding.LayoutTitleBarBinding
+import com.grkj.iscs_mc.util.SPUtils
+
+class TitleBar(ctx: Context, attrs: AttributeSet) : RelativeLayout(ctx, attrs) {
+
+    private var mBinding: LayoutTitleBarBinding
+
+    init {
+        val root = View.inflate(ctx, R.layout.layout_title_bar, this)
+        mBinding = LayoutTitleBarBinding.bind(root)
+
+        val attrSet = ctx.obtainStyledAttributes(attrs, R.styleable.TitleBar)
+
+        attrSet.getString(R.styleable.TitleBar_bar_title)?.let { mBinding.tvModuleName.text = it }
+
+        attrSet.getResourceId(R.styleable.TitleBar_bar_icon, 0).let {
+            mBinding.ivIcon.setBackgroundResource(it)
+        }
+
+        attrSet.recycle()
+
+        mBinding.tvUser.text = SPUtils.getLoginUser(ctx)?.userName
+    }
+
+    fun setTitle(title: String) {
+        mBinding.tvModuleName.text = title
+    }
+
+    fun setIcon(icon: Int) {
+        mBinding.ivIcon.setImageResource(icon)
+    }
+}

+ 1 - 1
app/src/main/res/drawable/item_rv_technology_sop_bg_normal.xml

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
 <shape xmlns:android="http://schemas.android.com/apk/res/android">
-    <corners android:radius="@dimen/common_radius_small" />
+    <corners android:radius="@dimen/common_radius_big" />
     <solid android:color="@color/common_bg_white_10" />
 </shape>

+ 1 - 1
app/src/main/res/layout/activity_home.xml

@@ -76,7 +76,7 @@
         app:layout_constraintLeft_toRightOf="@id/rl_menu"
         app:layout_constraintRight_toRightOf="parent"
         app:layout_constraintTop_toTopOf="parent"
-        android:padding="@dimen/page_padding">
+        android:padding="@dimen/common_spacing">
 
         <androidx.viewpager2.widget.ViewPager2
             android:id="@+id/vp"

+ 9 - 0
app/src/main/res/layout/fragment_material_home.xml

@@ -6,6 +6,14 @@
     android:layout_height="match_parent"
     tools:context=".view.fragment.MaterialHomeFragment">
 
+    <com.grkj.iscs_mc.view.widget.TitleBar
+        android:id="@+id/tb"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_marginBottom="@dimen/common_spacing"
+        app:bar_icon="@mipmap/material_management"
+        app:bar_title="@string/material_management" />
+
     <RelativeLayout
         android:id="@+id/rl_status"
         android:layout_width="match_parent"
@@ -20,6 +28,7 @@
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:layout_above="@id/rl_status"
+        android:layout_below="@id/tb"
         android:background="@drawable/item_rv_technology_sop_bg_normal">
 
         <RelativeLayout

+ 0 - 34
app/src/main/res/layout/fragment_material_management.xml

@@ -5,47 +5,13 @@
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:orientation="vertical"
-    android:padding="@dimen/common_spacing"
     tools:context=".view.fragment.MaterialManagementFragment">
 
-    <RelativeLayout
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content">
-
-        <ImageView
-            android:id="@+id/iv_icon"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_centerVertical="true" />
-
-        <TextView
-            android:id="@+id/tv_module_name"
-            style="@style/CommonTextView"
-            android:layout_centerVertical="true"
-            android:layout_marginLeft="@dimen/common_spacing_small"
-            android:layout_toRightOf="@id/iv_icon" />
-
-        <TextView
-            android:id="@+id/tv_user"
-            style="@style/CommonTextView"
-            android:layout_alignParentRight="true"
-            android:layout_centerVertical="true" />
-
-        <ImageView
-            android:layout_width="@dimen/common_icon_size"
-            android:layout_height="@dimen/common_icon_size"
-            android:layout_centerVertical="true"
-            android:layout_marginRight="@dimen/common_spacing_small"
-            android:layout_toLeftOf="@id/tv_user"
-            android:background="@mipmap/avatar" />
-    </RelativeLayout>
-
     <androidx.fragment.app.FragmentContainerView
         android:id="@+id/nav_host"
         android:name="androidx.navigation.fragment.NavHostFragment"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
-        android:layout_marginTop="@dimen/common_spacing"
         app:defaultNavHost="true"
         app:navGraph="@navigation/nav_graph" />
 </LinearLayout>

+ 33 - 0
app/src/main/res/layout/layout_title_bar.xml

@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/title_bar"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content">
+
+    <ImageView
+        android:id="@+id/iv_icon"
+        android:layout_width="@dimen/common_icon_size_big"
+        android:layout_height="@dimen/common_icon_size_big"
+        android:layout_centerVertical="true" />
+
+    <TextView
+        android:id="@+id/tv_module_name"
+        style="@style/CommonTextView"
+        android:layout_centerVertical="true"
+        android:layout_marginLeft="@dimen/common_spacing_small"
+        android:layout_toRightOf="@id/iv_icon" />
+
+    <TextView
+        android:id="@+id/tv_user"
+        style="@style/CommonTextView"
+        android:layout_alignParentRight="true"
+        android:layout_centerVertical="true" />
+
+    <ImageView
+        android:layout_width="@dimen/common_icon_size"
+        android:layout_height="@dimen/common_icon_size"
+        android:layout_centerVertical="true"
+        android:layout_marginRight="@dimen/common_spacing_small"
+        android:layout_toLeftOf="@id/tv_user"
+        android:background="@mipmap/avatar" />
+</RelativeLayout>

+ 5 - 0
app/src/main/res/values/attrs.xml

@@ -1,5 +1,10 @@
 <?xml version="1.0" encoding="utf-8"?>
 <resources>
+    <declare-styleable name="TitleBar">
+        <attr name="bar_title" format="string" />
+        <attr name="bar_icon" format="reference" />
+    </declare-styleable>
+
     <declare-styleable name="CommonBtn">
         <attr name="btn_name" format="string" />
         <attr name="btn_icon" format="reference" />

+ 1 - 0
app/src/main/res/values/dimens.xml

@@ -12,6 +12,7 @@
     <dimen name="common_spacing_big">15dp</dimen>
     <dimen name="common_spacing_small">5dp</dimen>
     <dimen name="common_spacing_smallest">2dp</dimen>
+    <dimen name="common_icon_size_big">18dp</dimen>
     <dimen name="common_icon_size">15dp</dimen>
     <dimen name="common_icon_size_small">12dp</dimen>