編輯:關於Android編程
復制代碼 代碼如下:
package org.david.dayandnightdemo.cor;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.graphics.Color;
import android.graphics.PixelFormat;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity implements OnClickListener {
private WindowManager mWindowManager;
private View myView;
private Button btn_dayAndnight;
private SharedPreferences skinSp;
private final static String DAY = "day";
private final static String NIGHT = "night";
private int flage = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mWindowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
setContentView(R.layout.activity_main);
init();
}
private void init() {
skinSp = this.getSharedPreferences("skinchange", Context.MODE_PRIVATE);
btn_dayAndnight = (Button) findViewById(R.id.btn_dayAndnight);
btn_dayAndnight.setOnClickListener(this);
String mode = skinSp.getString("skin", "");
if(mode!=null||!mode.equals("")){
if(mode.equals(NIGHT)){
night();
}else{
day();
}
}
}
@Override
public void onClick(View v) {
if(flage%2==0){
night();
btn_dayAndnight.setText("白天模式");
btn_dayAndnight.setTextColor(Color.WHITE);
flage++;
}else{
day();
btn_dayAndnight.setText("夜間模式");
btn_dayAndnight.setTextColor(Color.BLACK);
flage++;
}
}
public void night() {
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT,
LayoutParams.TYPE_APPLICATION,
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
params.gravity=Gravity.BOTTOM;
params.y=10;
if(myView==null){
myView=new TextView(this);
myView.setBackgroundColor(0x80000000);
}
mWindowManager.addView(myView, params);
Editor edit = skinSp.edit();
edit.putString("skin", NIGHT);
edit.commit();
}
public void day(){
if(myView!=null){
mWindowManager.removeView(myView);
Editor edit = skinSp.edit();
edit.putString("skin", DAY);
edit.commit();
}
}
public void removeSkin(){
if(myView!=null){
mWindowManager.removeView(myView);
}
}
@Override
protected void onDestroy() {
super.onDestroy();
String mode = skinSp.getString("skin", "");
if(mode.equals(NIGHT)){
removeSkin();
}
}
}
布局文件
復制代碼 代碼如下:
<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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<Button
android:id="@+id/btn_dayAndnight"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/btn_changeskin" />
</RelativeLayout>
APP的測試重點小部分在APP本身,大部分還是在網絡通信上(單機版除外)。所以在安卓APP測試過程中,網絡抓包非常重要,一般來說,app開發會采用HTTP協議、Webso
1. 何為1G/ 2G/ 3G/ 4G技術1.1. G代表什麼?G代表Generation的簡稱,有代的意思。1G代表作是大哥大,采用通信標准是模擬制式,只能進行語音通話
最近下了個攜程App,點開首頁看,注意到其按鈕在點擊的時候並不是我們經常看到的變色效果,而是先收縮,放開時,再回到原來的大小,感覺這個效果雖然小,但是感覺非常新穎,於是決
本文在《7種形式的Android Dialog使用實例》在這篇文章的基礎進行學習,具體內容如下1.概述 android原生控件向來以丑著稱(新推出的Material D