how to get customized alert dialog , like the one shown in image?

前端 未结 4 1760
别那么骄傲
别那么骄傲 2021-01-17 00:36

\"wanti want to build a customized dialog just like the one shown in image:

i

4条回答
  •  孤独总比滥情好
    2021-01-17 01:28

    You just have to inflate the Dialog with your xml file. I'll just give you a sample code, then you can easily follow

    private View mView;
    private Dialog mDialog;
    private LayoutInflater mInflater;
    

    Now create a function as :-

    private void showCustomDialog() {
        mInflater = (LayoutInflater) getBaseContext().getSystemService(
                LAYOUT_INFLATER_SERVICE);
        ContextThemeWrapper mTheme = new ContextThemeWrapper(this,
                R.style.YOUR_STYE);
    
        mView = mInflater.inflate(R.layout.YOUR_XML_LAYOUT_FILE, null);
        // mDialog = new Dialog(this,0); // context, theme
    
        mDialog = new Dialog(mTheme);
        mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        mDialog.setContentView(this.mView);
        mDialog.show();
    
        TextViiew someText = (TextView) mView.findViewById(R.id.textViewID);
        // do some thing with the text view or any other view 
    
    }
    

    Finally make sure you have the style as :-

    
    

    That's it .... you are done... just call this function where ever you want to show the custom dialog....

    Hope the explanation was useful....

提交回复
热议问题