編輯:關於Android編程
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { case KeyEvent.KEYCODE_VOLUME_DOWN: case KeyEvent.KEYCODE_VOLUME_UP: if (mCameraAppView.getVisibility() != View.VISIBLE) { return false; } Log.v(TAG,"onKeyDown event.getRepeatCount() "+event.getRepeatCount()); if (event.getRepeatCount() == 0) { event.startTracking(); return true; } return true; } return super.onKeyDown(keyCode, event); } 如果一直按著不放,通過打 log 可以看到 onKeyDown event.getRepeatCount() 0 onKeyDown event.getRepeatCount() 1 onKeyDown event.getRepeatCount() 2 onKeyDown event.getRepeatCount() 3 onKeyDown event.getRepeatCount() 4 onKeyDown event.getRepeatCount() 5 onKeyDown event.getRepeatCount() 6 onKeyDown event.getRepeatCount() 7 onKeyDown event.getRepeatCount() 8 onKeyDown event.getRepeatCount() 9 onKeyDown event.getRepeatCount() 10 onKeyDown event.getRepeatCount() 11 onKeyDown event.getRepeatCount() 12 …… 第二步,重載 onKeyLongPressed 函數,在這個函數中你可以添加你的處理 @Override public boolean onKeyLongPress(int keyCode, KeyEvent event) { Log.v(TAG,"key long pressed keyCode = "+keyCode); switch (keyCode) { case KeyEvent.KEYCODE_VOLUME_UP: case KeyEvent.KEYCODE_VOLUME_DOWN: Log.v(TAG,"KEYCODE_VOLUME_UP/DOWN long pressed"); lockLongPressKey = true; onShutterButtonLongPressed(); return true; default: break; } return super.onKeyLongPress(keyCode, event); }
@Override public boolean onKeyUp(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_VOLUME_UP: case KeyEvent.KEYCODE_VOLUME_DOWN: Log.v(TAG, "onKeyUp event.getRepeatCount() "+event.getRepeatCount()); if(lockLongPressKey){ lockLongPressKey = false; return true; } if (event.getRepeatCount() == 0) { Log.v(TAG, "prepare for onShutterButtonClick.."); if (mEnableRecordBtn && mReviewImage.getVisibility() != View.VISIBLE && mBgLearningMessageFrame.getVisibility() == View.GONE) { if (mShutterButton != null && mShutterButton.isEnabled()) { onShutterButtonFocus(false); collapseCameraControls();//fulin@20121101@fix PD1218 B121027-224 onShutterButtonClick(); } } } if (mCameraAppView.getVisibility() != View.VISIBLE) { return false; } return true; } return super.onKeyUp(keyCode, event); }
import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnLongClickListener; import android.widget.Button; import android.widget.Toast; public class MyActivity extends Activity implements OnLongClickListener{ Button button;//聲明按鈕的引用 public void onCreate(Bundle savedInstanceState) {//重寫的onCreate方法 super.onCreate(savedInstanceState); setContentView(R.layout.main); button = (Button) this.findViewById(R.id.button);//得到按鈕的引用 button.setTextSize(20); button.setOnLongClickListener(this);//注冊監聽 } public boolean onLongClick(View v) {//實現接口中的方法 if(v == button){//當按下的是按鈕時 Toast.makeText( this, "長時間按下了按鈕", Toast.LENGTH_SHORT ).show();//顯示提示 } return false; } }
0x00閱讀本文前,建議讀者首先閱讀Android加殼原理,參考文章Android中的Apk的加固(加殼)原理解析和實現。如果沒有看過這篇文章,本文理解起來比較困難。0x
EditText和AutoCompleteTextView設置文字選中顏色 大多數Android Rom上,文本選擇的背景色都是很好看的鮮綠色, 但是在某些垃圾的三星手機
想將Button和ListView分別放在屏幕的一左一右。單純使用android:gravity和android:layout_gravity不成功。於是涉及到Relat
1.修改SDK版本: 打開File--Project Structure... Modules--app--Properties