使用可见软件键盘进行的活动

发布于 2025-01-08 02:57:37 字数 147 浏览 3 评论 0原文

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

I've seen some similar questions here but haven't found what I was really looking for. I need to create a simple activity where the user must enter a number and return it to the main activity. The layout should contain only an edit text on the upper half of the screen and a software keyboard on the lower half of the screen. The activity should finish when the Done key is pressed on the keyboard. Will appreciate any links or code snippets to help resolve this issue.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

断念 2025-01-15 02:57:37

我建议您使用自定义对话框来执行此操作。

关键是,您想要键盘进行交互,并在按下数字时返回,不是吗?

如果想要一个示例,您可以创建一个对话框活动,如下所示:

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;

然后在创建时设置此内容:

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 时会关闭,并关闭对话框(返回到抛出的位置)

我希望它有帮助!

I recommend you use a Custom dialog to do it.

The point is, you want a keyboard to interaction, and return when a number is pressed, aren't you?

If want an example, you can create a Dialog Activity like:

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;

Then set the this content on create:

setContentView(R.layout.keypad);
    findViews();
    setListeners();

find views will be something like this:

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

And the dialog XML must have a table:

<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

So, when you launch the dialog, appear a menu with 9 numbers (in my case) whom dismiss when push 1 of then, and dismiss the dialog (return to the point where was throw)

I hope it help!!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文