出现弹出窗口后,键盘不会出现,父视图上的按钮可单击

时间:2013-01-30 15:45:12

标签: android

单击特定按钮后,屏幕上会出现一个弹出窗口。弹出窗口上有一个edittext对象,但我无法写入它,因为键盘没有出现。其次,弹出窗口父视图上的其他按钮仍然是可点击的。我该如何解决这些问题?我的代码:

edit_text_popup.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="10dip"
    android:background="@color/conn_text" >

    <EditText
        android:id="@+id/editTextInPopup"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/hello_world"
        android:padding="5dip"
        android:background="@color/blue3">
    </EditText>
    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:padding="10dip">
        <Button
            android:id="@+id/popupcommitbutton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/ok"/>

        <Button
            android:id="@+id/popupcancelbutton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/cancel"
            android:layout_alignParentRight="true" />
    </RelativeLayout>

</LinearLayout>

调用popup:

public class GroupConnections extends Activity implements OnClickListener {
    Category thiscat;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);     
        setContentView(R.layout.activity_group_connections);        
        View addMoreConnButton =findViewById(R.id.attachMorePeopleButton);
        View editPropButton = findViewById(R.id.editCategoryPropertiesButton);
        addMoreConnButton.setOnClickListener(this);
        editPropButton.setOnClickListener(this);

        //get selected category
        int catId = getIntent().getExtras().getInt("categoryid");
        thiscat = (Category)SocialRssModel.Instance().holders.get(catId);

        //set text views        
        TableRow tabler = (TableRow)findViewById(R.id.tableRow1);
        TextView cateNameTextView = (TextView)tabler.findViewById(R.id.numOfContentsTextView2);
        cateNameTextView.setText(thiscat.getName());

        tabler = (TableRow)findViewById(R.id.tableRow2);
        CheckBox enable = (CheckBox)tabler.findViewById(R.id.notificationCheckBox);
        enable.setChecked(thiscat.isSelected());
    }
    /**
     * Button listeners are specified
     */
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.attachMorePeopleButton:
                Intent i = new Intent(this, AddMoreConnections.class);
                startActivity(i);
                break;
            case R.id.editCategoryPropertiesButton:
                LayoutInflater layoutInflater = (LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
                View popupView = layoutInflater.inflate(R.layout.edit_text_popup, null);
                final PopupWindow editpopup = new PopupWindow(popupView,LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
                //specify cancel button
                View cancelbutton = popupView.findViewById(R.id.popupcancelbutton);
                cancelbutton.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View arg0) {
                        editpopup.dismiss();
                    }
                });
                //specify edittext
                editpopup.setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);
                editpopup.showAsDropDown(findViewById(R.id.editCategoryPropertiesButton), 0, -30);
                break;

            // More buttons go here (if any) ...
        }
    }
}

AndroidManifest中的Activity标记显示softInputMode未隐藏:

<activity
    android:name=".GroupConnections"
    android:label="@string/app_name" >
</activity>

2 个答案:

答案 0 :(得分:0)

我有类似的问题。尝试在manifest.xml中的activity标记中添加此行:

android:windowSoftInputMode="stateVisible"

将弹出对话框更改为活动,在manifest.xml中使用此代码,它将您的活动显示为Dialog,您可以将其作为常规活动启动但是它显示了这样的对话框,这将更容易显示自定义对话框:

<activity
            android:name=".view.MyDialog"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="stateVisible"
            android:theme="@android:style/Theme.Dialog" >
        </activity>

答案 1 :(得分:0)

我在以下链接中找到了解决方案:EditText On A Popup Window

添加以下命令editpopup.setFocusable(true);可以解决这两个问题。