Custom Dialog

borrowed from

https://blog.csdn.net/android_it/article/details/51161038

https://blog.csdn.net/oQiHaoGongYuan/article/details/50958659


Effect



style

<!--dialog-->
<style name="MyDialog" parent="android:style/Theme.Dialog">
    <item name="android:windowBackground">@android:color/transparent</item>
<!--是否在window之上-->
<item name="android:windowIsFloating">true</item>
</style>        

I wanted to omit this step in the code, but it does not operate on Dialog, but on ContextWrapper, so I dare not change too much, leave a hole, and do this in the future


layout

<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="20dp"
android:background="#fff"
android:textColor="@color/colorAccent"
android:text="我是自定义Dialog"/>                            

This stores a style in your dialog. I simply use the text view as the root layout here. The default is a centering effect.

If you want to customize the entire layout yourself, and you need the background to be gray by default, you can set the background to #66000000


dialog

public class MyDialog extends Dialog {

    public MyDialog(Context context) {
        super(context, R.style.MyDialog);
    }

    @Override
protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
setContentView(R.layout.my_dialog);
}                
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325645726&siteId=291194637