android 自定义键盘的安全性,自定义Android键盘焦点问题

我目前正在开发一个自定义键盘应用程序,该应用程序将针对使用DPad作为其主要输入设备的设备进行优化.

我的问题是当光标位于EditText字段并按下(例如KEYCODE_DPAD_DOWN)时,键盘视图没有接收焦点和KeyEvents.没有任何反应,或者有问题的EditText下面的元素会获得焦点.

以下是相关代码.

任何帮助将非常感激.我已经尝试解析SoftKeyboard示例以及KeyboardView.java以获取提示但没有成功.

谢谢,

布赖恩

MyKeyboard.java

public class MyKeyboard extends InputMethodService {

private static final String TAG = "MyKeyboard";

private MyKeyboardView mInputView = null;

@Override public void onCreate() {

super.onCreate();

}

@Override public View onCreateInputView() {

mInputView = (MyKeyboardView) getLayoutInflater().inflate(R.layout.input, null);

// attempts to make this focusable

mInputView.setClickable(true);

mInputView.setFocusableInTouchMode(true);

mInputView.setFocusable(true);

mInputView.setEnabled(true);

return mInputView;

}

@Override public View onCreateCandidatesView() {

super.onCreateCandidatesView();

return null;

}

@Override public void onStartInputView(EditorInfo info, boolean restarting) {

super.onStartCandidatesView(info, restarting);

}

@Override public void onFinishInput() {

super.onFinishInput();

}

@Override public void onDestroy() {

super.onDestroy();

}

}

MyKeyboardView.java

public class MyKeyboardView extends TableLayout implements View.OnClickListener, View.OnFocusChangeListener {

private static final String TAG = "MyKeyboardView";

private ArrayList charList = new ArrayList();

public MyKeyboardView(Context context) {

super(context);

populateKeyboard();

this.setOnFocusChangeListener(this);

this.setOnClickListener(this);

}

public MyKeyboardView(Context context, AttributeSet attrs) {

super(context, attrs);

populateKeyboard();

this.setOnFocusChangeListener(this);

this.setOnClickListener(this);

}

@Override

public void onClick(View arg0) {

Log.d(TAG, "onClick");

}

private void populateKeyboard() {

charList.add(new Character(','));

charList.add(new Character('.'));

charList.add(new Character('?'));

charList.add(new Character('

charList.add(new Character('>'));

charList.add(new Character((char) 0x2798)); // arrow

charList.add(new Character((char) 0x2798)); // arrow

charList.add(new Character((char) 0x2798)); // arrow

charList.add(new Character((char) 0x005F)); // underscore

for(char c = '@'; c < 'Z'; c++) {

charList.add(new Character(c));

Log.d(TAG, "char: " + c);

}

TableRow tr = null;

for(int i=0; i

if(i % 7 == 0) {

if(tr != null)

this.addView(tr);

tr = new TableRow(this.getContext());

tr.setGravity(Gravity.CENTER_HORIZONTAL);

}

TextView tv = new TextView(this.getContext());

tv.setPadding(21, 2, 21, 2);

tv.setText(charList.get(i).toString());

tv.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 22);

tv.setTextColor(Color.WHITE);

tv.setGravity(Gravity.CENTER);

tv.setFocusable(true);

tv.setEnabled(true);

tr.addView(tv);

}

if(tr.getChildCount() > 0)

this.addView(tr);

}

@Override

public void onFocusChange(View v, boolean hasFocus) {

Log.d(TAG, "mInputView onFocusChange " + (hasFocus ? "true" : "false"));

}

}

input.xml中

android:id="@+id/input"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_alignParentBottom="true"

android:background="#FF000000"

android:focusable="true" />

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值