Fully custom dialog in Android with the same look regardless device

好久不见. 提交于 2019-12-18 07:03:38

问题


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?


回答1:


Go for this

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
}

 }

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

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

Edited For Transparent Dialog

use In onCreate of dialog class

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

Cheers :):)




回答2:


You can specify Themes in views or activities. Have a look at this link




回答3:


create xml file. and use this java code.

                        info_dialog = new Dialog(ActivityName.this);
                        info_dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                        info_dialog.setContentView(R.layout.info);                          
                        info_dialog.show();



回答4:


For doing custom dialog look at the tutorial it is great http://developer.android.com/guide/topics/ui/dialogs.html about the borders see here http://developer.android.com/guide/topics/ui/dialogs.html you may also make use of this It have some great Ideas



来源:https://stackoverflow.com/questions/8894300/fully-custom-dialog-in-android-with-the-same-look-regardless-device

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!