desc:封装Topbar

main
xiaowusky 2 years ago
parent 5e54f22fad
commit 0883ef21c7

@ -1,6 +1,7 @@
package com.yinuo.safetywatcher.watcher
import android.view.View
import com.yinuo.safetywatcher.R
import com.yinuo.safetywatcher.databinding.ActivitySettingBinding
import com.yinuo.safetywatcher.watcher.base.BaseActivity
@ -15,5 +16,6 @@ class SettingActivity: BaseActivity() {
}
override fun initView() {
setTitle(getString(R.string.setting))
}
}

@ -20,4 +20,8 @@ abstract class BaseActivity : AppCompatActivity() {
open abstract fun generateContentView(): View
abstract fun initView()
fun setTitle(title: String) {
baseBinding.topBar.setTitle(title)
}
}

@ -1,9 +1,14 @@
package com.yinuo.safetywatcher.watcher.view
import android.app.Activity
import android.content.Context
import android.graphics.Color
import android.opengl.Visibility
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.LinearLayout
import com.yinuo.safetywatcher.R
import com.yinuo.safetywatcher.databinding.LayoutTopbarBinding
class CommonTopBar : LinearLayout {
constructor(context: Context?) : this(context, null)
@ -14,8 +19,26 @@ class CommonTopBar : LinearLayout {
defStyleAttr
)
var mBinding: LayoutTopbarBinding? = null
init {
//初始化方法
setBackgroundColor(Color.RED)
val root = LayoutInflater.from(context).inflate(R.layout.layout_topbar, this)
mBinding = LayoutTopbarBinding.bind(root)
// 初始化隐藏返回栏
mBinding?.backArea?.visibility = GONE
mBinding?.backArea?.setOnClickListener {
if (context is Activity) {
(context as Activity).finish()
}
}
}
open fun setTitle(title: String) {
mBinding?.backArea?.visibility = VISIBLE
mBinding?.title?.text = title
}
}

@ -0,0 +1,68 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="@dimen/_87dp"
android:background="@color/_242f4d"
android:gravity="center_vertical"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/back_area"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingStart="16dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/_31dp"
android:src="@mipmap/ic_back" />
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/_23dp"
android:text="Title"
android:textColor="@color/white"
android:textSize="@dimen/_36dp" />
</LinearLayout>
<Space
android:layout_width="0dp"
android:layout_height="1px"
android:layout_weight="1" />
<TextClock
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/_30dp"
android:textColor="@color/white"
android:format24Hour ="HH.mm a"
android:format12Hour ="hh.mm a"/>
<ImageView
android:id="@+id/battery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/_40dp"
android:src="@mipmap/ic_setting"/>
<ImageView
android:id="@+id/wifi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/_40dp"
android:src="@mipmap/ic_setting"/>
<ImageView
android:id="@+id/four_g"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/_40dp"
android:layout_marginEnd="@dimen/_36dp"
android:src="@mipmap/ic_setting"/>
</LinearLayout>

Binary file not shown.

After

Width:  |  Height:  |  Size: 601 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 859 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 694 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 670 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 343 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 490 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 606 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 563 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 409 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 399 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 727 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 994 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 833 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="_16dp">16px</dimen>
<dimen name="_87dp">87px</dimen>
<dimen name="_288dp">288px</dimen>
<dimen name="_536dp">536px</dimen>
@ -13,4 +14,10 @@
<dimen name="_13dp">13px</dimen>
<dimen name="_34dp">34px</dimen>
<dimen name="_185dp">185px</dimen>
<dimen name="_12dp">12px</dimen>
<dimen name="_18dp">18px</dimen>
<dimen name="_36dp">36px</dimen>
<dimen name="_31dp">31px</dimen>
<dimen name="_23dp">23px</dimen>
<dimen name="_40dp">40px</dimen>
</resources>
Loading…
Cancel
Save