• android夜间模式切换


    1.记录个最简单的夜间模式的实现

    2.styles.xml

      <style name="DayTheme" parent="AppTheme">
            <item name="color_title">@color/title_bai</item>
            <item name="color_background">@drawable/bg01</item>
        </style>
    
        <style name="NightTheme" parent="AppTheme">
            <item name="color_title">@color/title_ye</item>
            <item name="color_background">@drawable/bg02</item>
        </style>
    
        <style name="FragmentTheme1" parent="AppTheme">
            <item name="fragmentcolor_title">@color/fragment_textcolor1</item>
        </style>

    3.colors.xml

        <color name="title_bai">#000000</color>
        <color name="title_ye">#ffffff</color>
        <color name="background_bai">#ffffff</color>
        <color name="background_ye">#8e7d7d</color>
        <color name="fragment_textcolor1">#D43333</color>
        <color name="fragment_textcolor2">#71C41F</color>

    4.arrts.xml

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
    
       
            <attr name="color_title" format="color" />
            <attr name="color_background" format="color" />
            <attr name="fragmentcolor_title" format="color" />
    
    </resources>
    

      

    5.main.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:background="?attr/color_background"
        tools:context="com.example.guoxw.myapplication.MainActivity"
        android:weightSum="1">
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:orientation="horizontal">
    
            <Button
                android:id="@+id/btn1"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="match_parent"
                android:textColor="?attr/color_title"
                android:text="fragment1"/>
            <Button
                android:id="@+id/btn2"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:textColor="?attr/color_title"
                android:layout_height="match_parent"
                android:text="fragment2"/>
            <Button
                android:id="@+id/btn3"
                android:layout_width="0dp"
           android:textColor="?attr/color_title"
                android:layout_weight="1"
                android:layout_height="match_parent"
                android:text="activity2"/>
            <Button
                android:id="@+id/btn4"
                android:layout_width="0dp"
                android:textColor="?attr/color_title"
                android:layout_weight="1"
                android:layout_height="match_parent"
                android:text="切换"/>
        </LinearLayout>
    
        <FrameLayout
            android:id="@+id/fragmentlayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginBottom="?actionBarSize"
            android:layout_marginTop="?actionBarSize" />
    
         
    </LinearLayout>

    6.java-activity

      protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            if (Constant.isDay) {
                this.setTheme(R.style.DayTheme);
            } else {
                this.setTheme(R.style.NightTheme);
            }
            setContentView(R.layout.activity_main);
    }

    7.java --fragment

     @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
    
            Context ctxWithTheme = new ContextThemeWrapper(getActivity().getApplicationContext(),R.style.FragmentTheme1);
            LayoutInflater localLayoutInflater = inflater.cloneInContext(ctxWithTheme);
            ViewGroup rootView = (ViewGroup)localLayoutInflater.inflate(R.layout.fragment_fragment1, null, false);
    
            //view=inflater.inflate(R.layout.fragment_fragment1, container, false);
    
            return rootView;
        }

    8.链接:

    http://pan.baidu.com/s/1eSiU42Q
    今天多一点积累,明天少一分烦恼
  • 相关阅读:
    百度mp3地址解密码
    VB 在EXE后附加信息
    截屏函数
    Base64和StrToByte
    The Android ION memory allocator, DMABUF is mentioned as well
    DDC EDID 介绍
    Memory management for graphic processors TTM的由来
    科普 写display driver的必看 How video card works [2D的四种主要操作]
    GEM vs TTM
    DMABUF 背景介绍文章 Sharing buffers between devices
  • 原文地址:https://www.cnblogs.com/galibujianbusana/p/7066719.html
Copyright © 2020-2023  润新知