欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

android基礎(chǔ)教程之夜間模式實現(xiàn)示例

 更新時間:2014年02月24日 16:15:22   作者:  
這篇文章主要介紹了android的夜間模式實現(xiàn)示例,需要的朋友可以參考下

復(fù)制代碼 代碼如下:

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();           
        }
    }

}

布局文件

復(fù)制代碼 代碼如下:

<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>

相關(guān)文章

  • Android自定義控件之水平圓點加載進(jìn)度條

    Android自定義控件之水平圓點加載進(jìn)度條

    這篇文章主要為大家詳細(xì)介紹了Android自定義控件之水平圓點加載進(jìn)度條,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-06-06
  • 自定義toast外形,多次點擊不會總是彈出toast的實現(xiàn)方法

    自定義toast外形,多次點擊不會總是彈出toast的實現(xiàn)方法

    下面小編就為大家?guī)硪黄远xtoast外形,多次點擊不會總是彈出toast的實現(xiàn)方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-04-04
  • Android Listview多tab上滑懸浮效果

    Android Listview多tab上滑懸浮效果

    這篇文章主要為大家詳細(xì)介紹了Android Listview多tab上滑懸浮效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-11-11
  • Flutter開發(fā)中的路由參數(shù)處理

    Flutter開發(fā)中的路由參數(shù)處理

    在實際開發(fā)中,我們經(jīng)常會需要在頁面跳轉(zhuǎn)的時候攜帶路由參數(shù),典型的例子就是從列表到詳情頁的時候,需要攜帶詳情的 id,以便詳情頁獲取對應(yīng)的數(shù)據(jù)。同時,有些時候還需要返回時攜帶參數(shù)返回上一級,以便上級頁面根據(jù)返回結(jié)果更新。本篇將介紹這兩種情形的實現(xiàn)。
    2021-06-06
  • Android App調(diào)用MediaRecorder實現(xiàn)錄音功能的實例

    Android App調(diào)用MediaRecorder實現(xiàn)錄音功能的實例

    這篇文章主要介紹了Android App調(diào)用MediaRecorder實現(xiàn)錄音功能的實例,MediaRecorder非常強(qiáng)大,不僅能夠用來錄制音頻還可以錄制視頻,需要的朋友可以參考下
    2016-04-04
  • Android 異步加載圖片的實例代碼

    Android 異步加載圖片的實例代碼

    異步加載圖片主要是利用多線程進(jìn)行下載、圖片弱引用緩存和Handler操作UI進(jìn)行實現(xiàn)的。
    2013-05-05
  • Android自定義view仿QQ的Tab按鈕動畫效果(示例代碼)

    Android自定義view仿QQ的Tab按鈕動畫效果(示例代碼)

    這篇文章主要介紹了Android自定義view仿QQ的Tab按鈕動畫效果(示例代碼),本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考價值,需要的朋友可以參考下
    2021-01-01
  • Android 桌面Widget開發(fā)要點解析(時間日期Widget)

    Android 桌面Widget開發(fā)要點解析(時間日期Widget)

    總的來說,widget主要功能就是顯示一些信息。我們今天編寫一個很簡單的作為widget,顯示時間、日期、星期幾等信息。需要顯示時間信息,那就需要實時更新,一秒或者一分鐘更新一次
    2013-07-07
  • 關(guān)于Fragment?already?added問題的解決方案

    關(guān)于Fragment?already?added問題的解決方案

    這篇文章主要介紹了關(guān)于Fragment?already?added問題的解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-10-10
  • 一文詳解Android無需權(quán)限調(diào)用系統(tǒng)相機(jī)拍照

    一文詳解Android無需權(quán)限調(diào)用系統(tǒng)相機(jī)拍照

    這篇文章主要為大家介紹了Android無需權(quán)限調(diào)用系統(tǒng)相機(jī)拍照詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-03-03

最新評論