网友通过本文主要向大家介绍了android 自定义软键盘,android 自定义view,android 自定义控件,android 自定义dialog,android 自定义进度条等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
Android 测试自定义纯数字软键盘,android自定义
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" > <EditText android:id="@+id/editText1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_marginRight="24dp" android:ems="10" android:inputType="none" > <requestFocus /> </EditText> <android.inputmethodservice.KeyboardView android:id="@+id/keyboardview" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_marginTop="5.0dp" android:background="#ffffffff" android:focusable="true" android:keyBackground="@drawable/calculator_button_bg" android:keyTextColor="@color/black" android:keyTextSize="26.0sp" android:shadowColor="#ffffffff" android:shadowRadius="0.0" android:visibility="gone" /> </RelativeLayout>
hexkbd.xml
<?xml version="1.0" encoding="utf-8"?> <Keyboard xmlns:android="http://schemas.android.com/apk/res/android" android:background="#ffffffff" android:keyHeight="10%p" android:keyWidth="100%p" > <Row> <Key android:codes="55" android:keyEdgeFlags="left" android:keyLabel="7" /> <Key android:codes="56" android:keyLabel="8" /> <Key android:codes="57" android:keyLabel="9" /> </Row> <Row> <Key android:codes="52" android:keyEdgeFlags="left" android:keyLabel="4" /> <Key android:codes="53" android:keyLabel="5" /> <Key android:codes="54" android:keyLabel="6" /> </Row> <Row> <Key android:codes="49" android:keyEdgeFlags="left" android:keyLabel="1" /> <Key android:codes="50" android:keyLabel="2" /> <Key android:codes="51" android:keyLabel="3" /> </Row> <Row> <Key android:codes="46" android:keyEdgeFlags="left" android:keyLabel="." /> <Key android:codes="48" android:keyLabel="0" /> <Key android:codes="-5" android:isRepeatable="true" android:keyIcon="@drawable/sym_keyboard_delete" /> </Row> </Keyboard>
MainActivity.java
package com.example.yanlei.yl2; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.EditText; public class MainActivity extends Activity implements OnClickListener { CustomKeyboard mCustomKeyboard; EditText editText; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); editText = (EditText) findViewById(R.id.editText1); mCustomKeyboard = new CustomKeyboard(this, R.id.keyboardview, R.xml.hexkbd); mCustomKeyboard.registerEditText(R.id.editText1); } @Override public void onClick(View v) { switch (v.getId()) { default: break; } } }
CustomKeyboard.java
package com.example.yanlei.yl2; import android.app.Activity; import android.inputmethodservice.Keyboard; import android.inputmethodservice.KeyboardView; import android.inputmethodservice.KeyboardView.OnKeyboardActionListener; import android.text.Editable; import android.text.InputType; import android.view.MotionEvent; import android.view.View; import android.view.View.OnClickListener; import android.view.View.OnFocusChangeListener; import android.view.View.OnTouchListener; import android.view.WindowManager; import android.view.inputmethod.InputMethodManager; import android.widget.EditText; /** * When an activity hosts a keyboardView, this class allows several EditText's * to register for it. * * @author Maarten Pennings * @date 2012 December 23 */ class CustomKeyboard { /** A link to the KeyboardView that is used to render this CustomKeyboard. */ private KeyboardView mKeyboardView; /** A link to the activity that hosts the {@link #mKeyboardView}. */ private Activity mHostActivity; /** The key (code) handler. */ private