Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> android 隨筆記錄

android 隨筆記錄

編輯:關於Android編程




----返回--------
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK
&& event.getAction() == KeyEvent.ACTION_DOWN) {
back();
}
return super.onKeyDown(keyCode, event);
}

private void back() {
Intent intent = new Intent(Msg.this, MainActivity.class);
intent.putExtra("userName", userName);
intent.putExtra("userId", userId);
startActivity(intent);
this.finish();
}

----再按一次退出--------
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK
&& event.getAction() == KeyEvent.ACTION_DOWN) {
if ((System.currentTimeMillis() - exitTime) > 2000) {// 兩次操作間隔
Toast.makeText(getApplicationContext(),

R.string.exit,Toast.LENGTH_SHORT).show();
exitTime = System.currentTimeMillis();
} else {
finish();
System.exit(0);
}
return true;
}
return super.onKeyDown(keyCode, event);
}
------設置全屏--------------
AndroidManifest.xml
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"../>

------設置只能橫屏-------
android:screenOrientation="landscape"

----------圖片鋸齒 需要注意
android:minSdkVersion="8"
android:targetSdkVersion="17" /> 放到application底下就可以解決

-----------調用系統自帶播放器
Uri uri = Uri.parse(Constants.VIDEO_PATH);
// 調用系統自帶的播放器
Intent playIntent = new Intent(Intent.ACTION_VIEW);

playIntent.setDataAndType(uri, "video/mp4");
startActivity(playIntent);
----------調用安卓編寫的播放器
Intent localIntent = new Intent(CarDetail.this, WeiDianYing.class);

startActivity(localIntent);
//WeiDianYing.class
public class WeiDianYing extends Activity {
RelativeLayout weidianyingLayout;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.h_activity_wei_dian_ying);
this.weidianyingLayout = (RelativeLayout) findViewById(R.id.weidianying);

VideoView localVideoView = new VideoView(this);
String url = "android.resource://" + getPackageName() + "/"
+ R.raw.shuangchengji;
MediaController localMediaController = new MediaController(this);

localVideoView.setMediaController(localMediaController);
localMediaController.setMediaPlayer(localVideoView);
localVideoView.setVideoURI(Uri.parse(url));
RelativeLayout.LayoutParams localLayoutParams = new RelativeLayout.LayoutParams(
-1, -1);

this.weidianyingLayout.setGravity(17);
this.weidianyingLayout.addView(localVideoView, localLayoutParams);
localVideoView.start();

}
}

//Weidianying.xml

android:id="@+id/weidianying"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >


------------------打開html
WebView實例.loadUrl("file:///android_asset/moreinfo.html");
//設置全屏
wv.getSettings().setUseWideViewPort(true);
wv.getSettings().setLoadWithOverviewMode(true);


  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved