Android studio LSettingItem快速实现页面 “我的”或者“设置”页面 最新的!最新的!

Android studio LSettingItem快速实现页面 “我的”或者“设置”页面

最近想做个页面,但网上搜资料全是一七年甚至是之前的!现在这个是最新的,最新版Android studio 可用!
1、添加依赖

 implementation 'com.leon:lsettingviewlibrary:1.3.0'
 implementation 'de.hdodenhof:circleimageview:2.1.0'

从很早之前的文章看到compile 的,现在已经不用了。

2、布局 activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:leon="http://schemas.android.com/apk/res-auto"
    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:orientation="vertical"
    tools:context=".MainActivity">

    <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/e"
            app:civ_border_color="#FFFFFF"
            app: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/ic_money"
        leon:leftText="钱包" />

    <com.leon.lib.settingview.LSettingItem
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        leon:leftIcon="@drawable/ic_collect"
        leon:leftText="收藏" />

    <com.leon.lib.settingview.LSettingItem
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        leon:leftIcon="@drawable/ic_photo"
        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"
        android:theme="@style/MyCheckBox"
        leon:leftIcon="@drawable/ic_card"
        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/ic_face"
        leon:leftText="表情" />

    <com.leon.lib.settingview.LSettingItem
        android:id="@+id/item_six"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/MyCheckBox"
        leon:leftIcon="@drawable/ic_setting"
        leon:rightStyle="iconSwitch"
        leon:leftText="设置" />

    <com.leon.lib.settingview.LSettingItem
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        leon:isShowUnderLine="false"
        leon:leftIcon="@drawable/ofm_feedback_icon"
        leon:leftText="我的位置"
        leon:rightStyle="iconSwitch" />


</LinearLayout>

3、styles.xml 添加

<style name="MyCheckBox" parent="AppTheme">
        <item name="colorControlNormal">#CCCCCC</item>
        <item name="colorControlActivated">#0099CC</item>
</style>

4、MainActivity .java

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;

import com.leon.lib.settingview.LSettingItem;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //对一个控件进行点击事件
        LSettingItem one =(LSettingItem)findViewById(R.id.item_one);

        one.setmOnLSettingItemClick(new LSettingItem.OnLSettingItemClick() {
            @Override
            public void click() {
                Toast.makeText(MainActivity.this,"点击了钱包",Toast.LENGTH_SHORT).show();
            }
        });
    }
}

发布了17 篇原创文章 · 获赞 62 · 访问量 1129

猜你喜欢

转载自blog.csdn.net/cui_xiaoyu/article/details/105540206