考虑此DialogFragment:
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.DialogFragment
class TestDialog: DialogFragment() {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return inflater.inflate(R.layout.test_dialog, container)
}
}
和相应的布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Test Dialog" />
</LinearLayout>
[当我在Android 5上运行此命令时,“测试对话框”字符串上方的对话框中会有额外的空格:
在Android 6及更高版本上,没有额外的空间。为什么它会出现在Android 5上?这是Android 5支持库中的错误吗?有什么我可以做的吗?
此问题不会出现在创建对话框的地方
AlertDialog.Builder
您尝试在getWindow().requestFeature(Window.FEATURE_NO_TITLE);
上添加此
onCreateView()
吗?
我希望它将与您合作