Android 个人中心界面 及退出登陆

后来改良版:

想要源码 请到作者主页 看开源项目!!!

我又改进了第三版

 

涉及:

/**fresco 图片加载**/
implementation 'com.facebook.fresco:fresco:2.1.0'
/** TextView样式布局      **/
implementation 'com.github.lygttpod:SuperTextView:2.1.6'

第二版

布局如下:

<LinearLayout 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/bg_gray"
              android:orientation="vertical"
              tools:context="com.example.l.instructordome.PresonFragment">


    <LinearLayout
        android:background="@color/white"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <ImageView
            android:id="@+id/images_head"
            android:layout_width="80dp"
            android:layout_height="80dp"
            android:layout_marginBottom="10dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="10dp"
            android:scaleType="fitCenter"
            app:srcCompat="@mipmap/t0"/>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="vertical"
            android:weightSum="1">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="20dp"
                android:layout_weight="0.3"
                android:orientation="horizontal">

                <TextView
                    android:id="@+id/textView8"
                    android:layout_width="70dp"
                    android:layout_height="wrap_content"
                    android:text="昵称:"
                    android:textSize="18sp"/>

                <TextView
                    android:id="@+id/t_name"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="辅导员助手"
                    android:textSize="18sp"
                    android:textStyle="bold"/>
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0.3"
                android:orientation="horizontal">

                <TextView
                    android:id="@+id/textView9"
                    android:layout_width="70dp"
                    android:layout_height="wrap_content"
                    android:text="学号:"
                    android:textSize="18sp"/>

                <TextView
                    android:id="@+id/t_number"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="0.44"
                    android:text="******"
                    android:textSize="18sp"
                    android:textStyle="bold"/>
            </LinearLayout>

        </LinearLayout>

    </LinearLayout>

    <LinearLayout
        style="@style/wrap_layout"
        >
        <!-- 上圆角-->
        <LinearLayout style="@style/top_layout">

            <TextView
                style="@style/usertext"
                android:text="个人资料"/>

            <ImageView style="@style/img_arrow"/>
        </LinearLayout>

        <!-- 分割线 -->
        <View
            style="@style/bg_line"
            android:layout_height="2px"/>
        <!-- 无圆角-->
        <LinearLayout style="@style/mid_layout">

            <TextView
                style="@style/usertext"
                android:text="我的申请"/>

            <ImageView style="@style/img_arrow"/>
        </LinearLayout>

        <!-- 分割线 -->
        <View
            style="@style/bg_line"
            android:layout_height="2px"/>     <!-- 分割线 -->

        <!-- 无圆角-->
        <LinearLayout style="@style/mid_layout">

            <TextView
                style="@style/usertext"
                android:text="消息通知"/>

            <ImageView style="@style/img_arrow"/>
        </LinearLayout>
        <!-- 分割线 -->
        <!-- 无圆角-->

        <View
            style="@style/bg_line"
            android:layout_height="2px"/>
        <!-- 下圆角-->
        <LinearLayout style="@style/bottom_layout">

            <TextView
                style="@style/usertext"
                android:text="问题与反馈"/>

            <ImageView style="@style/img_arrow"/>
        </LinearLayout>

    </LinearLayout>


    <!-- 全圆角-->
    <LinearLayout style="@style/wrap_layout">

        <LinearLayout style="@style/single_layout">

            <TextView
                style="@style/usertext"
                android:text="设置"/>

            <ImageView style="@style/img_arrow"/>
        </LinearLayout>

    </LinearLayout>

    <Button
        android:id="@+id/btn_quit"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/login_btn_login"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        android:layout_marginTop="10dp"
        android:background="?attr/colorPrimary"
        android:text="退出登陆"
        android:textColor="@color/white"
        android:textSize="18sp"/>


</LinearLayout>

style.xml

    <!-- 上圆角样式 -->
    <style name="top_layout" parent="base_layout">
        <item name="android:background">@drawable/top_layout_selector</item>
    </style>
    <!--无圆角样式  -->
    <style name="mid_layout" parent="base_layout">
        <item name="android:background">@drawable/mid_layout_selector</item>
    </style>
    <!-- 下圆角样式 -->
    <style name="bottom_layout" parent="base_layout">
        <item name="android:background">@drawable/bottom_layout_selector</item>
    </style>
    <!-- 全圆角样式 -->
    <style name="single_layout" parent="base_layout">
        <item name="android:background">@drawable/single_layout_selector</item>

top_layout_selector.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:state_pressed="true" android:drawable="@drawable/top_select"></item>
    <item android:state_focused="true" android:drawable="@drawable/top_select"></item>
    <item android:drawable="@drawable/top_unselect"></item>
</selector>

top_select.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <solid android:color="@color/sblue"/>
    <corners android:topRightRadius="8dp" android:topLeftRadius="8dp"/>
</shape>

top_unselect.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <solid android:color="@color/white"/>
    <corners android:topRightRadius="8dp" android:topLeftRadius="8dp"/>
</shape>

其他圆角同理套路一下

目前刚刚写 只写了界面,和退出登陆

和获取当前用户

  MyUser userInfo = BmobUser.getCurrentUser(MyUser.class);
        String s_name=userInfo.getByname();
        String s_number=userInfo.getUsername();
        t_name.setText(s_name);
        t_number.setText(s_number);

注意: 我们 实例对象上的 和bomb 云后端表 列名的大小写 ,还是用bmob 给的函数吧,不严报错

  @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn_quit:
                BmobUser.logOut();
                startActivity(new Intent(getActivity(),LoginActivity.class));
                break;
        }
    }

这里我来补充一下

如果你在activity里写线程了,退出登陆时,一定要记得销毁,否则报错。

如: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.example.aigsharedome.JavaBean.MyUser.

这里我动态更新Textview ,循环一直请求,所以出错。

注: 在fagment 碎片里 获取当前内容 用getActivity() 方法。以前 初学时,报错。

MyActivityManager 这种方式 适合sqlite 这种云数据库,就不适用了, 这一种 将activity 压栈,退出登陆时,将所有的activity 全部销毁。

public class MyActivityManager {
    private static MyActivityManager instance;
    private Stack<Activity> activityStack;//activity栈
    private MyActivityManager() {
    }
    //单例模式
    public static MyActivityManager getInstance() {
        if (instance == null) {
            instance = new MyActivityManager();
        }
        return instance;
    }
    //把一个activity压入栈中
    public void pushOneActivity(Activity actvity) {
        if (activityStack == null) {
            activityStack = new Stack<Activity>();
        }
        activityStack.add(actvity);
        Log.d("MyActivityManager ", "size = " + activityStack.size());
    }
    //获取栈顶的activity,先进后出原则
    public Activity getLastActivity() {
        return activityStack.lastElement();
    }
    //移除一个activity
    public void popOneActivity(Activity activity) {
        if (activityStack != null && activityStack.size() > 0) {
            if (activity != null) {
                activity.finish();
                activityStack.remove(activity);
                activity = null;
            }
        }
    }
    //退出所有activity
    public void finishAllActivity() {
        if (activityStack != null) {
            while (activityStack.size() > 0) {
                Activity activity = getLastActivity();
                if (activity == null) break;
                popOneActivity(activity);
            }
        }
    }
}

 

  • 12
    点赞
  • 169
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 21
    评论
以下是一个简单的安卓个人界面的代码示例: XML布局文件: ```xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <!-- 头像 --> <ImageView android:id="@+id/profile_image" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/profile_image"/> <!-- 用户名 --> <TextView android:id="@+id/username_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="用户名"/> <!-- 简介 --> <TextView android:id="@+id/bio_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="个人简介"/> <!-- 编辑个人资料按钮 --> <Button android:id="@+id/edit_profile_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="编辑个人资料"/> </LinearLayout> ``` Java代码: ```java public class ProfileActivity extends AppCompatActivity { private ImageView profileImage; private TextView usernameText; private TextView bioText; private Button editProfileButton; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_profile); profileImage = findViewById(R.id.profile_image); usernameText = findViewById(R.id.username_text); bioText = findViewById(R.id.bio_text); editProfileButton = findViewById(R.id.edit_profile_button); // 设置头像和用户名 profileImage.setImageResource(R.drawable.profile_image); usernameText.setText("用户名"); // 设置个人简介 String bio = "这里是我的个人简介,可以编辑以展示更多信息。"; bioText.setText(bio); // 点击编辑个人资料按钮 editProfileButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // 跳转到编辑个人资料页面 Intent intent = new Intent(ProfileActivity.this, EditProfileActivity.class); startActivity(intent); } }); } } ``` 这个界面包括一个头像、一个用户名、一个个人简介和一个编辑个人资料按钮。你可以根据需要进行修改和扩展。
评论 21
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

江南:-)

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值