QMUI添加左边右边图片(可以添加自己的图片)
1、xml
<?xml version="1.0" encoding="utf-8"?>
<com.qmuiteam.qmui.widget.QMUIWindowInsetLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
tools:context=".activity.VipDetailsMainActivity">
<com.qmuiteam.qmui.widget.QMUITopBarLayout
android:id="@+id/vipTopBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/black"
android:fitsSystemWindows="true" />
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/qmui_topbar_height"
android:fitsSystemWindows="true">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/tv_text_tile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="13dp"
android:layout_marginTop="27dp"
android:text="VIP会员特权"
android:textColor="@color/black"
android:textSize="15sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginStart="17dp"
android:layout_marginTop="15dp"
android:layout_marginEnd="17dp"
app:layout_constraintTop_toBottomOf="@+id/tv_text_tile">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.appcompat.widget.AppCompatImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/my_item1" />
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="9dp"
android:text="广告特权"
android:textColor="#3F3F3F"
android:textSize="13sp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.appcompat.widget.AppCompatImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/my_item1" />
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="9dp"
android:text="搜索功能"
android:textColor="#3F3F3F"
android:textSize="13sp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.appcompat.widget.AppCompatImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/my_item1" />
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="9dp"
android:text="自定义类别"
android:textColor="#3F3F3F"
android:textSize="13sp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.appcompat.widget.AppCompatImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/my_item1" />
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="9dp"
android:text="分类预算"
android:textColor="#3F3F3F"
android:textSize="13sp" />
</LinearLayout>
</LinearLayout>
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/appCompatTextView10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="13dp"
android:layout_marginTop="27dp"
android:text="VIP会员套餐"
android:textColor="@color/black"
android:textSize="15sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/linearLayout" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_vip_list"
android:layout_width="match_parent"
android:layout_height="120dp"
android:layout_marginStart="13dp"
android:layout_marginTop="17dp"
android:layout_marginEnd="13dp"
app:layout_constraintTop_toBottomOf="@+id/appCompatTextView10" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/appCompatTextView11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="13dp"
android:layout_marginTop="10dp"
android:text="到期按包年自动续费,可随时取消"
android:textColor="#A8A8A8"
android:textSize="10sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/rv_vip_list" />
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/appCompatButtonView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="17dp"
android:layout_marginTop="27dp"
android:layout_marginEnd="17dp"
android:background="@drawable/bt_my"
android:text="立即开通¥99"
android:textSize="15sp"
android:textStyle="bold"
app:layout_constraintTop_toBottomOf="@+id/appCompatTextView11" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center"
app:layout_constraintTop_toBottomOf="@+id/appCompatButtonView1">
<CheckBox
android:id="@+id/cb_check_log"
android:layout_width="15dp"
android:layout_height="15dp"
android:background="@drawable/check_user_privacy_bg"
android:button="@null" />
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:text="开通前请阅读《服务协议》以及《隐私政策》" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</com.qmuiteam.qmui.widget.QMUIWindowInsetLayout>
2、java代码
//添加自己的图片改变文字颜色
vipTopBarLayout.setTitle("VIP会员").setTextColor(getColor(R.color.vip_title))
vipTopBarLayout.addLeftImageButton(R.drawable.back_white, 1)
.setOnClickListener { onBackPressed() }
//左边添加按钮
vipTopBarLayout.addRightImageButton(R.drawable.detail2_v1, 1).setOnClickListener { }