Android 点击换头像(拍照和从相册选择)
首先是layout里的代码,但这之前需要在build.gradle里加两行代码,主要是圆形图片和别的按钮啥的,你也可以改成自己的,不加圆形图片用系统原来的图片也是可以的。
implementation 'com.leon:lsettingviewlibrary:1.3.0'
implementation 'de.hdodenhof:circleimageview:2.1.0'
- my.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:leon="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_marginBottom="16dp"
android:background="#fff"
android:gravity="center"
android:orientation="vertical">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/profile_image"
android:layout_width="96dp"
android:layout_height="96dp"
android:src="@drawable/picc"
leon:civ_border_color="#FFFFFF"
leon:civ_border_width="2dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="10dp"
android:text="小飞象"
android:textSize="16sp" />
</LinearLayout>
<com.leon.lib.settingview.LSettingItem
android:id="@+id/item_one"
android:layout_width="match_parent"
android:layout_height="wrap_content"
leon:leftIcon="@drawable/picc"
leon:leftText="钱包" />
<com.leon.lib.settingview.LSettingItem
android:layout_width="match_parent"
android:layout_height="wrap_content"
leon:leftIcon="@drawable/picc"
leon:leftText="收藏" />
<com.leon.lib.settingview.LSettingItem
android:layout_width="match_parent"
android:layout_height="wrap_content"
leon:leftIcon="@drawable/picc"
leon:leftText="相册"
leon:rightStyle="iconHide"/>
<com.leon.lib.settingview.LSettingItem
android:id="@+id/item_four"
android:layout_width="match_parent"
android:layout_height="wrap_content"
leon:leftIcon="@drawable/picc"
leon:leftText="卡包"
leon:rightStyle="iconCheck"/>
<com.leon.lib.settingview.LSettingItem
android:id="@+id/item_five"
android:layout_width="match_parent"
android:layout_height="wrap_content"
leon:leftIcon="@drawable/picc"
leon:leftText="表情" />
<com.leon.lib.settingview.LSettingItem
android:id="@+id/item_six"
android:layout_width="match_parent"
android:layout_height="wrap_content"
leon:leftIcon="@drawable/picc"
leon:leftText="设置"
leon:rightStyle="iconSwitch" />
<com.leon.lib.settingview.LSettingItem
android:layout_width="match_parent"
android:layout_height="wrap_content"
leon:isShowUnderLine="false"
leon:leftIcon="@drawable/picc"
leon:leftText="我的位置"
leon:rightStyle="iconSwitch" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
下面的xml文件是弹出的小框的layout文件
2.layout_bottom_dialog.xml
<?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="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
an