zoukankan      html  css  js  c++  java
  • 白天黑夜模式转换

    public class MainActivity extends Activity{

        private WindowManager wm;

        private View myView;

        private Button button;

        private SharedPreferences sp;

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

            wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);

            setContentView(R.layout.activity_main);

            sp = this.getSharedPreferences("skinchange", Context.MODE_PRIVATE);

            button = (Button) findViewById(R.id.btn_dayAndnight);

            String mode = sp.getString("skin", "");

            if(mode!=null||!mode.equals("")){

                if(mode.equals(NIGHT)){

                    night();

                }else{

                    day();

                }

            }

            button.setOnClickListener(new OnClickListener() {

                
                @Override
                public void onClick(View v) {

            SharedPreferences sp2=getSharedPreferences("aa", MODE_APPEND);
                    int flage=sp2.getInt("bb", 0);
                    if(flage%2==0){

                        night();

                        button.setText("白天模式");

                        button.setTextColor(Color.WHITE);

                        flage++;

                    }else{

                        day();

                        button.setText("夜间模式");

                        button.setTextColor(Color.BLACK);

                        flage++;

                    }

            SharedPreferences sp1=getSharedPreferences("aa", MODE_APPEND);
                    Editor ed=sp1.edit();
                    ed.putInt("bb", flage);
                    ed.commit();
        
                }

            });

        }
        
    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);
            }
            wm.addView(myView, params);
            Editor edit = sp.edit();
            edit.putString("skin", NIGHT);
            edit.commit();
        }

        public void day(){
            if(myView!=null){
                wm.removeView(myView);
                Editor edit = sp.edit();
                edit.putString("skin", DAY);
                edit.commit();
            }
        }
    }

  • 相关阅读:
    MySQL-Linux升级MySQL
    查看linux 版本
    mysql 密码找回方法
    CentOS7.6利用systemctl添加自定义系统服务
    centos7.6下定时监测MySQL进程终止后自动重启的方法
    Linux实操篇-Linux磁盘分区、挂载
    阿里云centos7.6下MongoDB安装和配置
    Linux中文件权限 chmod、u+x、u、r、w、x分别代表什么
    ABP 发布以后nlog4.NET写入不到日志文件里
    Android studio gradle 下载很缓慢的解决方法,gradle版本不对
  • 原文地址:https://www.cnblogs.com/wbp0818/p/5303698.html
Copyright © 2011-2022 走看看