无论设备如何,Android 中的完全自定义对话框都具有相同的外观 [英] Fully custom dialog in Android with the same look regardless device

查看:11
本文介绍了无论设备如何,Android 中的完全自定义对话框都具有相同的外观的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无论操作系统主题如何,我都必须构建一个在不同设备上看起来完全相同的对话框.目前,我创建了一个 AlertDialog 并调用 alertDialog.setView(myLayout).这将创建一个包含我的视图的对话框.但是,对话框的某些部分(外部和边界线)仍然是基于操作系统的,它们在我的三星或 HTC 中看起来不同.

I have to build a dialog that looks exactly the same across different devices regardless of the OS theme. At the moment, I created an AlertDialog and I call alertDialog.setView(myLayout). This creates a dialog with my view. However, some parts of the dialog box (outer part and border line) are still OS based and they look different in my Samsung or HTC.

有没有办法创建实际的盒子?

Is there anyway to create the actual box?

推荐答案

去做这个

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

public class FullyscutomDialo extends Dialog{

public FullyscutomDialo(Context context) {
    super(context);
    // TODO Auto-generated constructor stub
}

@Override
public void dismiss() {
    //do what you need before closing here
    super.dismiss();
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //set your custom layout here
    //use layout attribut just like activity
}

 }

然后使用两行从活动中显示它(可能是 onclickevent 等)

then use two line to show it from activity(May be onclickevent etc)

         FullyscutomDialo hh=new FullyscutomDialo (this);
         hh.show()

为透明对话框编辑

在对话框类的onCreate中使用

use In onCreate of dialog class

 this.getWindow().setBackgroundDrawable(new ColorDrawable(0));

干杯:):)

这篇关于无论设备如何,Android 中的完全自定义对话框都具有相同的外观的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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