0

글쎄,이 질문을하는 것과 같은 질문은 없을 것입니다. 그러나 Google의 모든 질문/답변과 거의 모든 Android 입력 방법 웹 페이지를 읽는 중 아직도 문제가 있습니다.android 용 사용자 정의 키보드 만들기

최종 목표는 맞춤 키보드를 만드는 것입니다. 물론, 내 언어에는 특정 입력 방법이 있습니다.

하지만 이번에는 키보드가 팝업되었을 때 내 사용자 정의보기를 표시하고 싶습니다. qwerty.xml 파일을 기반으로 기본 레이아웃을 팝했습니다.이 파일은 다음과 같습니다.

XML/qwerty.xml는

그리고 InputMethodService를 확장 내 수업에서

<Keyboard xmlns:android="http://schemas.android.com/apk/res/android" 
android:keyWidth="10%p" 
android:horizontalGap="0px" 
android:verticalGap="0px" 
android:keyHeight="60dp" 
> 
<Row android:rowEdgeFlags="bottom"> 
    <Key android:codes="999" android:keyLabel="Settings" android:keyWidth="20%" android:keyEdgeFlags="left"/> 
    <Key android:codes="44" android:keyLabel="," android:keyWidth="7%p" /> 
    <Key android:codes="47" android:keyLabel="/" android:keyWidth="7%p" /> 
    <Key android:codes="32" android:keyLabel="SPACE" android:keyWidth="30%p" android:isRepeatable="true"/> 
    <Key android:codes="-5" android:keyLabel="DEL" android:keyWidth="18%p" android:isRepeatable="true"/> 
    <Key android:codes="-4" android:keyLabel="DONE" android:keyWidth="18%p" android:keyEdgeFlags="right"/> 
</Row> 
, 내가 입력 뷰를 작성,이 코드가 있습니다.

private KeyboardView myKeyView; 
private Keyboard keyboard; 

@Override 
public View onCreateInputView() { 
    myKeyView = (KeyboardView)getLayoutInflater().inflate(R.layout.keyboard, null); 
    keyboard = new Keyboard(this, R.xml.qwerty); 
    myKeyView.setKeyboard(keyboard); 
    myKeyView.setOnKeyboardActionListener(this); 
    return myKeyView; 
} 

물론 내 원본에 내 사용자 지정보기를 적용 할 때 문제가있어서. 방금 ​​다른 측면에서 약간의 노력을했습니다. XML에서 설정 키를 누르면,

<Key android:codes="999" android:keyLabel="Settings" android:keyWidth="20%" android:keyEdgeFlags="left"/> 

그것은 SettingsActivity

@Override 
public void onKey(int primaryCode, int[] keyCodes) { 
    if(primaryCode == 999) { 
     openSettings(); 
    } 
} 

public void openSettings() 
{ 
    Intent intent = new Intent(this, WRKeySettings.class); 
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
    startActivity(intent); 
} 

그것은 여기까지 잘 작동 호출합니다,하지만 난이보기 문제에입니다.

안드로이드 개발자와 기사를 읽는 것으로 생각하면 키보드보기를 확장하여 내 사용자 정의보기를 만들 수 있으며이 방법에서는 어떻게 든 onDraw()를 사용하여 키를 그릴 수 있습니다. 하지만 이렇게하는 데 많은 어려움을 겪고 있습니다.

모든 의견을 기뻐할 것입니다. 감사.

+0

과 같은 키보드 이벤트를 사용자 정의하는 데 더 많은 도움이됩니다.이 질문을 명확하게 이해하기 위해 프로그래밍 방식으로 다른 레이아웃을 만드시겠습니까? 기존 항목을 변경 하시겠습니까? 다른 응용 프로그램에서 동일한 "키보드"를 다시 사용 하시겠습니까? 키를 "다시 그리기"는 할 수 있지만 동일한 기능을 사용하거나 레이아웃에보기를 추가하고 창을 "다시 실행"할 수 있습니다. 가능한 한 구체적으로 수행하십시오. – Bonatti

답변

1

키보드를 사용자 정의하려면 xml 폴더의 "qwerty"와 레이아웃 폴더의 키보드를 수정해야합니다. 나는 몇 가지 예 보여줄 것 :

이 레이아웃 폴더

<?xml version="1.0" encoding="UTF-8"?> 
<com.example.keyboard.MyKeyboardView 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/keyboard" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:layout_alignParentBottom="true" 
android:keyPreviewLayout="@layout/preview" 
android:keyBackground="@drawable/key_selector" 
android:shadowRadius="0.0" 
android:keyTextColor="#000000" 
/> 

에 간다를 그리고 이것은 XML 폴더에 간다 : 당신이 말한 것처럼

<?xml version="1.0" encoding="utf-8"?> 
<Keyboard xmlns:android="http://schemas.android.com/apk/res/android" 
android:keyWidth="10%p" 
android:keyHeight="8%p"> 

<Row android:verticalGap="1%p" android:horizontalGap="0.5%p" android:keyWidth="9.6%p"> 
    <Key android:codes="113" android:keyLabel="q" /> 
    <Key android:codes="119" android:keyLabel="w" /> 
    <Key android:codes="101" android:keyLabel="e" /> 
    <Key android:codes="114" android:keyLabel="r" /> 
    <Key android:codes="116" android:keyLabel="t" /> 
    <Key android:codes="121" android:keyLabel="y" /> 
    <Key android:codes="117" android:keyLabel="u" /> 
    <Key android:codes="105" android:keyLabel="i" /> 
    <Key android:codes="111" android:keyLabel="o" /> 
    <Key android:codes="112" android:keyLabel="p" /> 
</Row> 
<Row android:verticalGap="1%p" android:horizontalGap="0.5%p" android:keyWidth="9.6%p"> 
    <Key android:codes="97" android:keyLabel="a" android:keyEdgeFlags="left" android:horizontalGap="5%p" /> 
    <Key android:codes="115" android:keyLabel="s" /> 
    <Key android:codes="100" android:keyLabel="d" /> 
    <Key android:codes="102" android:keyLabel="f" /> 
    <Key android:codes="103" android:keyLabel="g" /> 
    <Key android:codes="104" android:keyLabel="h" /> 
    <Key android:codes="106" android:keyLabel="j" /> 
    <Key android:codes="107" android:keyLabel="k" /> 
    <Key android:codes="108" android:keyLabel="l" /> 
</Row> 
<Row android:verticalGap="1%p" android:horizontalGap="0.5%p" android:keyWidth="9.6%p"> 
    <Key android:codes="3"  android:keyIcon="@drawable/keyboard_shift_off_normal" 
     android:keyWidth="13.7%p"/> 
    <Key android:codes="122" android:keyLabel="z" android:horizontalGap="1%p"/> 
    <Key android:codes="120" android:keyLabel="x" /> 
    <Key android:codes="99"  android:keyLabel="c" /> 
    <Key android:codes="118" android:keyLabel="v" /> 
    <Key android:codes="98"  android:keyLabel="b" /> 
    <Key android:codes="110" android:keyLabel="n" /> 
    <Key android:codes="109" android:keyLabel="m" /> 
    <Key android:codes="-5"  android:keyIcon="@drawable/sym_keyboard_delete_dim" 
     android:keyWidth="13.7%p" 
     android:horizontalGap="1%p"/> 
</Row> 
<Row android:verticalGap="1%p" android:horizontalGap="0.5%p" android:keyWidth="9.6%p"> 
    <Key android:codes="-16" android:keyIcon="@drawable/keyboard_symbol" 
     android:keyWidth="18.7%p"/> 
    <Key android:codes="44"  android:keyLabel="," android:horizontalGap="1%p"/> 
    <Key android:codes="32"  android:keyIcon="@drawable/sym_keyboard_feedback_space" android:keyWidth="40%p"/> 
    <Key android:codes="46"  android:keyLabel="."/> 
    <Key android:codes="-3"  android:keyIcon="@drawable/keyboard_go" 
     android:keyWidth="18.5%p" android:horizontalGap="1%p"/> 
</Row> 
</Keyboard> 

, 당신은 키보드에서 클래스를 확장 할 수 있습니다 레이아웃과 비슷하지만 onTouch, onLongKeyPress,

+0

불행히도, 이것은 내가 원하는 특정 답변이 아닙니다. 이 문제를 해결할 수있는 방법을 찾으려고 노력할 것입니다. – luopleming

관련 문제