smile908

导航

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

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 2022-08-16 13:46  smile908  阅读(125)  评论(0编辑  收藏  举报