AlertDialog中的资源ID#0x0 [英] Resource ID #0x0 in AlertDialog
本文介绍了AlertDialog中的资源ID#0x0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在kotlin文件中添加了AlertDialog
,但出现异常
I adding an AlertDialog
in kotlin file, but get exception
btnLogin.setOnClickListener { view ->
login()
}
fun login() {
val builder = AlertDialog.Builder(this@LoginActivity)
builder.setView(R.layout.layout_loading_dialog)
val dialog = builder.create()
dialog.show()
}
例外
android.content.res.Resources$NotFoundException: Resource ID #0x0
at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:195)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2133)
at android.content.res.Resources.getLayout(Resources.java:1142)
at android.view.LayoutInflater.inflate(LayoutInflater.java:421)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="20dp">
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:id="@+id/textView"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="4"
android:gravity="center"
android:text="Please wait! This may take a moment." />
</LinearLayout>
推荐答案
在我修改为以下代码后,它可以正常工作.
It works fine after I modified to below code.
var dialogs = Dialog(this)
dialogs.requestWindowFeature(Window.FEATURE_NO_TITLE)
dialogs.getWindow().setBackgroundDrawable(ColorDrawable(Color.WHITE));
dialogs.setCancelable(false)
dialogs.setContentView(R.layout.layout_loading_dialog)
dialogs.show()
不知道为什么.
这篇关于AlertDialog中的资源ID#0x0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文