編輯:關於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: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: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. Fragment概述Fragment從Android v3.0版本開始引入隨著界面布局的復雜化,處理起來也更加的復雜,引入Fragment可以把activity拆分
第一步 :獲取ShareSDK 為了集成ShareSDK,您首先需要到ShareSDK官方網站注冊並且創建應用,獲得ShareSDK的Appkey,然後到SDK的下載頁
前言最近在做按鈕的時候遇到在給按鈕設置一張圖片作為背景的同時還要自己定義圓角,最簡單的做法就是直接切張圓角圖作為按鈕就可以了,但是如果不這樣該怎麼辦呢,看代碼:下面來看效