Reputation: 9425
I have Google this proplem, but none of the answers works for me.
This is the style of my AlertDialog
<style name="dialog_full_screen">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowFrame">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
<item name="android:windowFullscreen">true</item>
<item name="android:backgroundDimEnabled">true</item>
</style>
This is the code to show it.
val alertDialog = AlertDialog.Builder(this, R.style.dialog_full_screen).apply {
setCancelable(true)
}.create()
alertDialog.apply {
val wlp = window!!.attributes
wlp.gravity = Gravity.BOTTOM
wlp.flags = wlp.flags and WindowManager.LayoutParams.FLAG_DIM_BEHIND.inv()
val displayMetrics = DisplayMetrics()
windowManager.defaultDisplay.getMetrics(displayMetrics)
wlp.width = displayMetrics.widthPixels
wlp.height = WindowManager.LayoutParams.WRAP_CONTENT
window!!.attributes = wlp
}
alertDialog.show()
The following code is layout
<LinearLayout
android:id="@+id/linear_layout_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
style="@style/CenterInConstraintLayout"
tools:ignore="MissingConstraints">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@drawable/index_play_page_icon_comments_null"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/homepage_no_comments"
android:textColor="@color/color_gray_dark2"
android:textSize="@dimen/font_size_14"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
android:gravity="center">
<EditText
android:id="@+id/edit_text_comment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:maxLength="150"
android:hint="@string/homepage_hint_comment"
android:textColorHint="@color/color_gray_dark2"
android:background="@null"
android:importantForAutofill="no" />
<ImageView
android:id="@+id/image_view_send"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginEnd="30dp"
/>
</LinearLayout>
This AlertDialog
can show properly, but i can't show soft keyboard
Upvotes: 0
Views: 484
Reputation: 26
alertDialog.window.clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM)
Upvotes: 1
Reputation: 156
Give the EditText the type of softkeyboard you want, otherwise default will get applied
// Get the Edit text box to put into the dialog
final EditText input = findViewById(R.id.edit_text_comment)
// set the type of input entered, this would be for entry of a number digit keyboard
input.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_NORMAL);
...
input.requestFocus();
alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
alertDialog.show();
There is also question posted for similar situation here: when using AlertDialog.Builder with EditText, the Soft Keyboard doesn't pop or else try this: How to show soft-keyboard when edittext is focused
Upvotes: 0