smile908

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

论应用首页的返回按钮的设计

1:页面布局就一个返回的图标,使用的是imageView
<?xml version="1.0" encoding="utf-8"?>
<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:orientation="vertical"
tools:context=".LoginActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<ImageView
android:id="@+id/return_button"
//自定义控件建议自己设置控件的宽度和高度
android:layout_width="39dp"
android:layout_height="33dp"
//设置背景颜色
android:background="@drawable/bth_ripple_mask"
android:clickable="true"
//设置的图标样式,一个svg形式的返回控件
app:srcCompat="@drawable/ic_resource_return" />
</LinearLayout>
</LinearLayout>

@drawable/bth_ripple_mask的样式
<?xml version="1.0" encoding="utf-8"?>
<ripple
xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@android:color/darker_gray"><!--点击之后的颜色 必须要-->
<item
android:id="@android:id/mask"
android:drawable="@android:color/white"/>
</ripple>

@drawable/ic_resource_return图标的设计
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="48"
android:viewportHeight="48">
<path
android:pathData="M12.9998,8L6,14L12.9998,21"
android:strokeLineJoin="round"
android:strokeWidth="4"
android:fillColor="#00000000"
android:strokeColor="#333"
android:strokeLineCap="round"/>
<path
android:pathData="M6,14H28.9938C35.8768,14 41.7221,19.6204 41.9904,26.5C42.2739,33.7696 36.2671,40 28.9938,40H11.9984"
android:strokeLineJoin="round"
android:strokeWidth="4"
android:fillColor="#00000000"
android:strokeColor="#333"
android:strokeLineCap="round"/>
</vector>

最后一步,登陆逻辑的实现
package com.example.example;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;

public class LoginActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
//写返回功能
ImageView backOfBirthday = (ImageView) findViewById(R.id.return_button);
backOfBirthday.setOnClickListener(new View.OnClickListener()

{
@Override
public void onClick (View v){
Intent intentReturnUp = new Intent(LoginActivity.this, MainActivity.class);
startActivity(intentReturnUp);
}
});
}
}


posted on   smile908  阅读(128)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
点击右上角即可分享
微信分享提示