几个 Android 软键盘问题

发布于 2024-10-08 12:52:43 字数 200 浏览 8 评论 0原文

这是一种转发,我对任何违反规则的行为表示歉意,但我对 Android 手机上的软键盘有几个问题:

1)我有一个 Android 应用程序,有几个不同的视图(用户在它们之间切换)。我如何确定哪个是当前视图?我需要获取当前视图来执行隐藏虚拟键盘的代码。

2)如何检查当前是否正在显示虚拟键盘(以便我可以过滤各种硬键的操作)?

谢谢, R。

This is kind of a repost, and I apologize for any broken rules, but I have a couple of questions about the soft keyboard on Android phones:

1) I have an Android app with a couple different views (that the user switches between). How can I determine which is the current view?? I need to get the current view to execute the code that hides the virtual keyboard.

2) How can I check whether the virtual keyboard is currently being displayed (so I can filter the actions of my various hard keys)??

Thanks,
R.

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

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

发布评论

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

评论(1

一向肩并 2024-10-15 12:52:43

1)
public class ViewIdentification extends Activity Implements OnFocusChangeListener{

EditText _edt1;
EditText _edt2;
EditText _edt3;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    _edt1 = (EditText)findViewById(R.id.EditText01);
    _edt1.setOnFocusChangeListener(ViewIdentification.this);
    _edt2 = (EditText)findViewById(R.id.EditText02);
    _edt2.setOnFocusChangeListener(ViewIdentification.this);
    _edt3 = (EditText)findViewById(R.id.EditText03);    
    _edt3.setOnFocusChangeListener(ViewIdentification.this);


}

@Override
public void onFocusChange(View v, boolean hasFocus) {
    // TODO Auto-generated method stub

       if(v == _edt1 && hasFocus == true){

        Toast.makeText(ViewIdentification.this, "The First EditText is focused now", Toast.LENGTH_LONG).show();

       }else if(v == _edt2 && hasFocus == true){

        Toast.makeText(ViewIdentification.this, "The Second EditText is focused now", Toast.LENGTH_LONG).show();

       }else if(v == _edt3 && hasFocus == true){

        Toast.makeText(ViewIdentification.this, "The Third EditText is focused now", Toast.LENGTH_LONG).show();

       }

}

}

注意:通过这种方式我们可以知道哪个视图获得焦点。

2)

这可以通过计算活动的大小(最后聚焦视图所在的位置)来完成。

1)
public class ViewIdentification extends Activity implements OnFocusChangeListener{

EditText _edt1;
EditText _edt2;
EditText _edt3;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    _edt1 = (EditText)findViewById(R.id.EditText01);
    _edt1.setOnFocusChangeListener(ViewIdentification.this);
    _edt2 = (EditText)findViewById(R.id.EditText02);
    _edt2.setOnFocusChangeListener(ViewIdentification.this);
    _edt3 = (EditText)findViewById(R.id.EditText03);    
    _edt3.setOnFocusChangeListener(ViewIdentification.this);


}

@Override
public void onFocusChange(View v, boolean hasFocus) {
    // TODO Auto-generated method stub

       if(v == _edt1 && hasFocus == true){

        Toast.makeText(ViewIdentification.this, "The First EditText is focused now", Toast.LENGTH_LONG).show();

       }else if(v == _edt2 && hasFocus == true){

        Toast.makeText(ViewIdentification.this, "The Second EditText is focused now", Toast.LENGTH_LONG).show();

       }else if(v == _edt3 && hasFocus == true){

        Toast.makeText(ViewIdentification.this, "The Third EditText is focused now", Toast.LENGTH_LONG).show();

       }

}

}

NOTE : In this way we can get to know which view is focused .

2)

This can be done by calculating the size of the activity ( the location at which the last focused view is at ) .

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