【问题标题】:Add custom style in Android Dialog在 Android Dialog 中添加自定义样式
【发布时间】:2018-12-24 08:17:22
【问题描述】:

我在 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>

还有我的 kotlin 代码

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代码的sn-p:

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

我该如何解决这个问题?谢谢

【问题讨论】:

  • 如您所见,我尝试在 Kotlin 中找到解决方案。在java中,我知道如何解决这个问题@Sergey

标签: android kotlin android-styles android-dialog


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-07-19
    • 2023-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多