• Android开发 解决AlertDialog中的EditText无法调出输入法的问题


    在AlertDialog中使用自定义的View,如果View中有EditText,在上面点击,默认是跳不出软键盘的,不是焦点的问题。
    解决方法,有两种,一是把AlertDialog换成Dialog,但这么一来,对话框的最外层会多出一个框,顶部还会空几十个DP,当然可以用setBackgroundDrawable(new ColorDrawable(0))把背景设为透明,隐藏掉边框,但是上面空着的几十个DP还在,对话框就不是在屏幕居中了。
    代码:

    Dialog ad = new Dialog(context);
    ad.show();
    Window window = ad.getWindow();
    window.setBackgroundDrawable(new ColorDrawable(0)); 
    window.setContentView(R.layout.cancel_sos_dialog);

    最好的办法是第二种:

    AlertDialog ad = new AlertDialog.Builder(context).create();
    ad.setView(ManagerDialogLayout_.build(context,ad));
    ad.show();
    Window window = ad.getWindow();
    window.setContentView(ManagerDialogLayout_.build(context,ad));

    在调用show方法前先调用setView(layout),show后再调用window.setContentView(layout),两个Layout布局应该是相同的。

    至于原因,暂时不明,但是确实解决了问题,在EditText上点击,可以调出软键盘,输入法了。

    2013年1月6日:第一种方法的BUG,解决方法:
    使用自定义的Style:

    <style name="CustomDialogStyle" parent="@Android:style/Theme.Dialog">
    <item name="android:windowFrame">@null</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:background">@android:color/transparent</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:backgroundDimEnabled">true</item>
    <item name="android:backgroundDimAmount">0.6</item>
    </style>
    
    Dialog ad = new Dialog(context,R.style.CustomDialogStyle);
  • 相关阅读:
    git
    build and set proxy in Ubuntu
    export a java project to runable jar
    Remove openjdk in Ubuntu/Configure jdk and running adb in 64-bit Ubuntu
    When you install printer in Ubuntu, just need a ppd file.
    Ubuntu user switch
    Enable SSHD on Ubuntu
    web测试实践——day01
    白盒测试实践-day04
    白盒测试实践-day03
  • 原文地址:https://www.cnblogs.com/zhujiabin/p/5624106.html
Copyright © 2020-2023  润新知