-1

I have a layout which contains an EditText input field and on top of this layout i'm popping up an AlertDialog(Advertisement). The problem is that SoftKeyBoard is not popping up when click on the EditText. Is there any work around to achieve this requirement?

enter image description here

Layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_secondary"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="inova.lk.com.librarytestapp.main.SecondaryActivity">

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="20dp"
        android:layout_margin="20dp"
        android:hint="Enter Name"
        android:focusableInTouchMode="true"
        android:layout_centerInParent="true"/>
</RelativeLayout>

AlertDialog:

final Dialog dialog = new Dialog(activity);

dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
   dialog.setContentView(inova.lk.com.inapplibrary.R.layout.custom_dialog_layout);
dialog.setCancelable(false);

Window window = dialog.getWindow();
window.setFlags(
        WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
        WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
);

window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

WindowManager.LayoutParams wmlp = dialog.getWindow().getAttributes();
wmlp.width = Utility.dpToPx(320);
wmlp.height = Utility.dpToPx(50);

dialog.show();

UPDATE*****

I'm developing an advertisement SDK like google adz. AlertDialog is my adz banner. Banner on top of edittext layout is one scenario. Therefore I want a solution that will not require users who use my SDK to do any changes by their side.

2 Answers2

0

put these lines before dialog.show();

try{ 
      dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
   }catch (Exception e){
      e.printStackTrace();
      }
Divyesh Patel
  • 2,576
  • 2
  • 15
  • 30
  • This works if the EditText contain inside of the AlertDialog. Thanks – Milan Jayawardane Apr 06 '17 at 08:34
  • I'm developing an advertisement SDK like google adz. AlertDialog is my adz banner. Banner on top of edittext layout is one scenario. Therefore I want a solution that will not require users to do any changes by their side. Thanks – Milan Jayawardane Apr 07 '17 at 06:20
  • so you want to show keyboard when your alert dialog ads load in screen? – Divyesh Patel Apr 07 '17 at 06:23
  • Actually this is a one scenario. If a developer use my SDK to show a top banner in his page which contains EditText input fields then he can't interact with those input fields(SoftKeyBoard is not popping up) until he close the banner. But onclick, scroll like function are working without any problem. – Milan Jayawardane Apr 07 '17 at 06:29
  • It's similar to this problem http://stackoverflow.com/questions/28331247/keep-focus-on-edittext-after-opening-popup-window – Milan Jayawardane Apr 07 '17 at 06:31
  • As I mentioned before, here they are talking about a different issue. It's a scenario where EditText is in the PopUp Dialog. In my case popup dialog doesn't have any input field but popup dialog is popping up on a layout which contain a input field. Thanks – Milan Jayawardane Apr 07 '17 at 06:47
  • above link does not allow to get focus in dialog. so your edittext remain focused after popup dialog – Divyesh Patel Apr 07 '17 at 06:50
0

i'm popping up an AlertDialog(Advertisement).

Why you have to use an AlertDialog? Since your Advertisement is placed on top of the layout always, you may not need an AlertDialog, instead just use a FrameLayout and place it above the top of your layout.

Darish
  • 11,032
  • 5
  • 50
  • 70
  • I'm developing a SDK and there are adz types (like google adz). For example top banner, bottom banner, full screen banner, etc. if I provide a custom view then developers can place that view anywhere in the layout. So that i won't be able to force developers to put top banners, bottom banners, etc. – Milan Jayawardane Apr 06 '17 at 08:32