代码之家  ›  专栏  ›  技术社区  ›  BekaKK

在Android对话框中添加自定义样式

  •  0
  • BekaKK  · 技术社区  · 7 年前

    我在kotlin中创建了自定义对话框类。一切都很完美,但现在,我尝试添加我的定制风格。这是我的风格代码

     <style name="DialogTheme" parent="Theme.AppCompat.Light.Dialog">
    
        <item name="android:layout_width">fill_parent</item>
        <item name="android:layout_height">fill_parent</item>
        <item name="android:windowBackground">@color/transparent_15</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowIsFloating">false</item>
    
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:backgroundDimEnabled">true</item>
    
        <item name="colorPrimary">@color/black</item>
        <item name="colorPrimaryDark">@color/black</item>
        <item name="colorAccent">@color/light_blue</item>
    
    </style>
    

    class LoadingProgress(context: Context) : Dialog(context) {
    
        private var imageView: ImageView? = null
        private var message: TextView? = null
    
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            setCancelable(false)
            setCanceledOnTouchOutside(false)
            setContentView(R.layout.sp_loading_dialog)
            imageView = findViewById<View>(R.id.loading_image_view) as ImageView?
            message = findViewById<View>(R.id.loading_message) as TextView?
    
        }
    
        override fun show() {
            super.show()
            (imageView!!.background as AnimationDrawable).start()
    
        }
    }
    

    在java中,我知道如何添加自定义样式,但我不能在kotlin中重写java代码。

    下面是我的java代码片段:

    public LoadingProgress(@NonNull Context context) {
        super(context, R.style.DialogTheme);
    }
    

    我怎样才能解决这个问题?谢谢

    1 回复  |  直到 7 年前
        1
  •  0
  •   Sergio    7 年前

    尝试更改的调用构造函数 Dialog :

    class LoadingProgress(context: Context) : Dialog(context, R.style.DialogTheme) { ... }