Dialog学习实例

本文提供了一个简单的Android Dialog学习实例,包括调用部分和XML配置。作者正深入研究如何自定义AlertDialog的Theme,但目前尚无进展。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

1调用部分

public class RenameDialog {
	private Context context;
	public RenameDialog(Context context){
		this.context = context;
	}

	public void showExitsDialog() {
		final Dialog dialog = new Dialog(context); //, R.style.dialog);

		// 取得自定义View
		LayoutInflater layoutInflater = LayoutInflater.from(context);
		View unlinkOKLayout = layoutInflater.inflate(R.layout.mydialogly, null);

		Button okButton = (Button) unlinkOKLayout.findViewById(R.id.btnOk);
		Button cancelButton = (Button) unlinkOKLayout.findViewById(R.id.btnCancel);

		dialog.setContentView(unlinkOKLayout);
		dialog.show();
		dialog.setCanceledOnTouchOutside(true);

		okButton.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				dialog.cancel();
			}
		});
		cancelButton.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				dialog.cancel();
			}
		});
	}
}

2 xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="320dp"
    android:layout_height="480dp"
    android:background="#3FFF2FdF"
    android:orientation="vertical" >

    <RelativeLayout
        android:layout_width="320dp"
        android:layout_height="38dp" >

        <TextView
            android:id="@+id/titleId"
            android:layout_width="wrap_content"
            android:layout_height="38dp"
            android:layout_centerVertical="true"
            android:layout_marginLeft="22dp"
            android:gravity="center"
            android:text="设置频道" />

    </RelativeLayout>

     <TextView
            android:layout_width="fill_parent"
            android:layout_height="4dp"
            android:background="#FF0A9DCD"
            />
    

    <RelativeLayout
        android:layout_width="320dp"
        android:layout_height="396dp" >
    </RelativeLayout>
    
    
    <TextView
            android:layout_width="fill_parent"
            android:layout_height="4dp"
            android:background="#FF0A9DCD" />
    
    
     <LinearLayout
        android:orientation="horizontal"
        android:layout_width="320dp"
        android:layout_height="38dp" >
        <Button 
            android:layout_width="159dp"
            android:layout_height="match_parent"
            android:id="@+id/btnOk"
            android:background="#3c000000"
            android:text="Ok"/>
        <TextView android:layout_width="2dp"
            android:layout_height="match_parent"
            android:background="#3c000000"/>
        <Button 
            android:layout_width="159dp"
            android:layout_height="match_parent"
            android:id="@+id/btnCancel"
            android:background="#3c000000"
            android:text="Cancel"/>
    </LinearLayout>

</LinearLayout>


 

以上是简单的一个例子,在继续研究如何自定义AlertDialog的Theme,目前还没有进展先做这些了。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值