如何在Android的警报对话框的右上角放置关闭按钮? [英] How to put close button at top corner in alert dialog box for android?

查看:69
本文介绍了如何在Android的警报对话框的右上角放置关闭按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Android的警报对话框的右上角放置关闭按钮?

How to put close button at top corner in alert dialog box for android?

在警报对话框的右上角放置关闭按钮.

put close button at right side top corner in alert dialog.

我在滚动和对话框中使用了以下代码

i have used below code for scroll and dialog box

<ScrollView 
        android:id="@+id/ScrollView01" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        xmlns:android="http://schemas.android.com/apk/res/android">

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:orientation="vertical"
   android:scrollbars="vertical" 
   android:scrollbarAlwaysDrawVerticalTrack="true" >

<ImageVieandroid:id="@+id/image"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignParentRight="true"
 android:layout_alignParentTop="true"
 android:layout_marginLeft="200dp"
 android:src="@drawable/ic_launcher" />

</RelativeLayout>

</ScrollView>

在Java编码中,我已经在下面的编码中使用了我想放一张图片以关闭对话框请帮助

in java coding i have used below coding i want to put a image to close the dialog box please help

public void onClick(View v) 
{
// TODO Auto-generated method stub
   switch (v.getId())
   {
    case R.id.How_to_use:

 final Dialog dialog = new Dialog(this);
 dialog.setContentView(R.layout.description);
 dialog.setTitle("How to use");
 TextView text = (TextView) dialog.findViewById(R.id.description);
 text.setText(R.string.Descr_How_to_use);
 ImageView image = (ImageView) dialog.findViewById(R.id.image);
 image.setImageResource(R.drawable.ic_launcher);
 image.setOnClickListener(new OnClickListener() 
 {
  // @Override
  public void onClick(View v) {
  dialog.dismiss();
  }
  });
 dialog.show();
 break;
 default:
 break;
 }

推荐答案

您必须创建自定义对话框

Yo have to create custom dialog

import android.app.Dialog;
import android.content.Context;

public class CustomDialog extends Dialog 
{

public CustomDialog(Context context) 
{
    super(context);
    setContentView(R.layout.dialog);
}

}

创建dialog.xml文件.根据您的要求进行设计.

create dialog.xml file. design according to your requirment.

这篇关于如何在Android的警报对话框的右上角放置关闭按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆