Fully custom dialog in Android with the same look regardless device

后端 未结 4 1598
离开以前
离开以前 2020-12-19 18:49

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

4条回答
  •  余生分开走
    2020-12-19 19:12

    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 :):)

提交回复
热议问题