找到一個觸摸屏不能相應觸摸,但顯示沒有問題的手機,寫了個小程序,用來給寶寶播放兒歌。android
Total Control http://tc.sigma-rt.com.cn/小程序
manifest.xml文件設置以下:app
<activity android:name=".FullscreenActivity" android:configChanges="orientation|keyboardHidden|screenSize" android:label="@string/app_name" android:theme="@style/FullscreenTheme" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.HOME" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>
按照下面代碼示例修改Activity的onResume方法dom
@Override protected void onResume() { /** * 設置爲橫屏 */ if(getRequestedOrientation()!=ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE){ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } super.onResume(); }
或者在配置文件中對Activity節點添加ide
android:screenOrientation屬性(landscape是橫向, portrait是縱向) android:launchMode="singleTask" android:screenOrientation="portrait">
view.setKeepScreenOn(true)
// 攔截系統熱鍵 @Override public boolean dispatchKeyEvent(KeyEvent event) { int key = event.getKeyCode(); Log.i(TAG, "[test] dispatchKeyEvent event = " + event); if (key == KeyEvent.KEYCODE_VOLUME_DOWN || key == KeyEvent.KEYCODE_VOLUME_UP) { Log.i(TAG, "[test] catch event!! return true! "); return true; } return super.dispatchKeyEvent(event); }
if ( event.getAction() == KeyEvent.ACTION_DOWN) { return true;// only response to key up }
File f = new File(Environment.getExternalStorageDirectory().getPath()+"/videohome/"); File[] temp_dirs = f.listFiles(); int count = 0; for(File dir : temp_dirs) { if (dir.isDirectory()) { count++; } } dirs = new File[count]; for(File dir : temp_dirs) { if (dir.isDirectory()) { Log.e("haha",dir.toString()); dirs[--count] = dir; } }
(new Random()).nextInt( files.length);
this.videoView = (VideoView)this.findViewById(R.id.videoView); //videoView.setMediaController(new MediaController(this)); final MediaController mc = new MediaController(this); mc.setVisibility(View.INVISIBLE); mc.setEnabled(false); videoView.setMediaController(mc); videoView.setVideoURI(Uri.parse(file.toURI().toString())); videoView.start(); videoView.requestFocus(); videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { 播放下一首 } }
android:layout_alignParentLeft="true" android:layout_alignParentRight="true" android:layout_alignParentBottom="true"
layout改成RelativeLayoutthis