如何在 Android 中使用顶部角落的关闭按钮进行活动? [英] How to have activity in Android with a close button at the top corner?
本文介绍了如何在 Android 中使用顶部角落的关闭按钮进行活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要一个活动,其中包含一个关闭按钮,即右上角的x"来关闭活动.任何关于此的示例都会非常有帮助.
I would like to have an activity which would consist of a close button i.e 'x' at the right top corner closing the activity. Any examples on this will be very much helpful.
推荐答案
在 manifest 中创建一个 Activity
和 Transparent 主题,如下所示:
make an Activity
with Transparent theme in manifest like this:
<activity android:name=".MyDialogActivity" android:theme="@style/Theme.Transparent" />
然后像这样定义布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<RelativeLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_margin="15dp" android:padding="2dp">
<!-- Contents will go here..-->
</RelativeLayout>
<Button android:layout_alignParentRight="true" android:text="X"
android:textColor="#FFF" android:background="@drawable/round_button_background"
android:gravity="center_vertical|center_horizontal"
android:layout_margin="5dp" android:layout_height="25dp"
android:layout_width="25dp" android:textSize="12sp" android:textStyle="bold"
android:onClick="cancelActivity" />
</RelativeLayout>
并在 drawable 中为您的关闭 Button
定义背景,如下所示:
and define a background for your close Button
in drawable like this:
round_button_background.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#9F2200" />
<stroke android:width="2dp" android:color="#FFF" />
</shape>
这篇关于如何在 Android 中使用顶部角落的关闭按钮进行活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文