具有可见软件键盘的活动

时间:2012-02-22 08:22:51

标签: android android-activity android-softkeyboard visible

我在这里看到了一些类似的问题,但没有找到我真正想要的东西。我需要创建一个简单的活动,用户必须输入一个数字并将其返回到主活动。布局应该只包含屏幕上半部分的编辑文本和屏幕下半部分的软件键盘。当按下键盘上的完成键时,活动应该完成。将欣赏任何链接或代码片段,以帮助解决此问题。

1 个答案:

答案 0 :(得分:1)

我建议您使用Custom dialog来执行此操作。

重点是,你想要一个键盘进行交互,并在按下一个数字时返回,不是吗?

如果想要一个例子,你可以创建一个Dialog Activity,如:

public class Keypad extends Dialog

protected static final String TAG = "Keypad" ;
private final View keys[] = new View[9];
private View keypad;
private int tecla = 0;

然后在create:

上设置此内容
setContentView(R.layout.keypad);
    findViews();
    setListeners();

查找视图将是这样的:

keypad = findViewById(R.id.keypad);
    keys[0] = findViewById(R.id.keypad_1); ...

对话框XML必须有一个表:

<TableRow>
    <Button android:id="@+id/keypad_1" android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:onClick="keypadClick"
    android:text="keypadClick"></Button>
    <Button android:id="@+id/keypad_2"
        android:text="2" >
    </Button>
    <Button android:id="@+id/keypad_3"
        android:text="3" >
    </Button>
</TableRow> ... Etc

因此,当您启动对话框时,会出现一个包含9个数字的菜单(在我的情况下),当推送1时,它会被忽略,并关闭对话框(返回到抛出点)

我希望它有所帮助!!