Android 点击换头像(拍照和从相册选择)

这篇博客介绍了如何在Android应用中实现在点击后切换头像的功能,包括从布局代码到权限设置,以及使用相机和相册获取图片的步骤。涉及到的代码包括XML布局文件的修改、AndroidManifest.xml中权限的添加、Fragment中的实现以及动画效果的配置。
摘要由CSDN通过智能技术生成

Android 点击换头像(拍照和从相册选择)
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
首先是layout里的代码,但这之前需要在build.gradle里加两行代码,主要是圆形图片和别的按钮啥的,你也可以改成自己的,不加圆形图片用系统原来的图片也是可以的。

 implementation 'com.leon:lsettingviewlibrary:1.3.0'
 implementation 'de.hdodenhof:circleimageview:2.1.0'
  1. 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
  • 17
    点赞
  • 79
    收藏
    觉得还不错? 一键收藏
  • 12
    评论
评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值