1、首先,这个返回键是一个ImageView控件,其代码如下所示,设定它的clickable元素为true,这样点击就会有效果:
<ImageView
android:id="@+id/return_button"
android:layout_width="39dp"
android:layout_height="33dp"
android:background="@drawable/bth_ripple_mask"
android:clickable="true"
app:srcCompat="@drawable/ic_resource_return" />
2、它的背景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>
3、这个ImageView控件设定的图片为ic_resource_return,它是一个svg图片,其代码如下:
<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>
4、最后给这个控件写监听即可,这里让这个控件实现点击后返回上一级的功能:
ImageView backOfBirthday = (ImageView)findViewById(R.id.return_button);
backOfBirthday.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intentReturnUp = new Intent(Oneone.this, UpClass.class);
startActivity(intentReturnUp);
}
});
|