接下来,previous,键盘上方的按钮完成 [英] Next,Previous,Done buttons above keyboard

查看:251
本文介绍了接下来,previous,键盘上方的按钮完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这个问题之前<一问href=\"http://stackoverflow.com/questions/21305618/how-to-get-keyboard-with-next-$p$pvious-and-done-buttons-at-the-top-of-keyboard\">here.但是,有没有办法找到。

I know this question is asked before here. But there was no solution found.

我要的是有接下来,previous和Done按钮键盘上方
(我知道它模仿iPhone的键盘,但我为它的无奈要求)。

What I want is to have Next,Previous and Done buttons above the keyboard ( I know its mimicking iphone keyboard,but I m helpless its requirement ).

就像这样:
 

Like this :

现在我已经试过是:

于是,我花了三个按钮于一体的布局和分配财产的android:alignParentBottom =真正的
在清单中添加的android:windowSoftInputMode =adjustResize

So,I took three buttons in one layout and assigned property android:alignParentBottom="true" and in manifest add android:windowSoftInputMode="adjustResize".

看起来像这样::标签

Which look like this ::

和我所做的,移动并使用下一个,previous按钮是:

And What I did to move to and from using "next" "previous button is :

int next=1,prev=1;
public boolean onTouch(View arg0, MotionEvent arg1){                
            prev=next=1;                
            return false;
        }
});
edUserName.setOnTouchListener(new View.OnTouchListener(){
        public boolean onTouch(View arg0, MotionEvent arg1){
            prev=next=2;
            return false;
        }
});
edCity.setOnTouchListener(new View.OnTouchListener(){
        public boolean onTouch(View arg0, MotionEvent arg1){
            prev=next=3;
            return false;
        }
 });
btnNext.setOnClickListener(new View.OnClickListener(){          
        public void onClick(View arg0) {                
            if(next==1){    
                next++;     
                prev++;
                edUserName.requestFocus();                          
            }else if(next==2){
                next++;
                prev++;
                edCity.requestFocus();   
            }
        }
});
btnPrevious.setOnClickListener(new View.OnClickListener(){
        public void onClick(View arg0) {                
            if(prev==2){
                prev--;
                next--;
                edName.requestFocus();
            }else if(prev==3){
                prev--;
                next--;
                edUserName.requestFocus();
            }
        }
 });

这让我来回移动使用next和previous按钮。

This allows me to move to and fro using next and previous buttons.

现在的问题:


  1. 我知道它有点脏。请指导如果有更好的方法来使用下一个和previous按钮来回移动。

  1. I know its little dirty. Please guide if any better way to move to and fro using next and previous buttons.

我要显示的按钮,只有当键盘是可见的,否则隐藏它们。我怎样才能做到这一点。

I want to show buttons only when keyboard is visible otherwise hide them. How can I do this.?

完成按钮,我需要隐藏键盘它的表现,对此我想这一点,但是,它不是有时工作。

"Done" Button, i need to hide keyboard it its showing, for which i tried this, But, its not working sometimes. :

InputMethodManager IMM =(InputMethodManager)getSystemService
(Context.INPUT_METHOD_SERVICE);

如果(IMM!= NULL){

imm.toggleSoftInput(0,InputMethodManager.HIDE_IMPLICIT_ONLY);

}

如何隐藏的建议。

请帮我在这。

感谢。

推荐答案

我知道你说这是一个要求,但这些要求只是不会成为可能。首先,有没有回调或方法来检查或观看输入法的可见性。有一些黑客在那里,人们会建议,但他们只是 - 黑客。你不应该依靠他们。

I know you say it's a requirement, but those requirements just aren't going to be possible. Firstly, there's no callback or method to check or watch the visibility of the input method. There are some hacks out there that people will suggest, but they're just that -- hacks. You shouldn't rely on them.

其次,为您的焦点遍历是,Android内置了对诸如此类的事情支持pretty不错。只看的TextView / EditText上的 nextFocusDown 以及类似的属性。在大多数情况下,你甚至不需要指定这些由于Android是找出适合你的正确的顺序相当不错。如果您需要以编程方式做到这一点,你可以使用 requestFocus()方法方法:

Secondly, as for your focus traversal, fortunately Android has pretty good built in support for that sort of thing. Look at the nextFocusDown and similar attributes on TextView/EditText. In most cases you don't even have to specify these as Android is quite good at figuring out the right order for you. If you need to do it programmatically, you can use the requestFocus() method:

editText.requestFocus(View.FOCUS_DOWN);

或者你可以使用 FOCUS_UP 转到previous视图。

Or you can use FOCUS_UP to go to the previous view.

编辑:此外,还可以使用属性的inputType =TEXT | textNoSuggestions摆脱对大多数输入法的建议吧(虽然他们不尊重它必需​​的,并且很多都没有)

Also, you can use the attribute inputType="text|textNoSuggestions" to get rid of the suggestions bar on most input methods (although they are not required to respect it, and many don't).

这篇关于接下来,previous,键盘上方的按钮完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆