如何与在右上角关闭按钮在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.
推荐答案
作出活动
透明主题清单如下:
make an Activity
with Transparent theme in manifest like this:
<activity android:name=".MyDialogActivity" android:theme="@style/Theme.Transparent" />
再这样定义布局:
and then define layout like this:
<?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>
和定义背景为你的亲密在绘制这样的一个按钮
:
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屋!
查看全文