Android开发-软件版本升级与黑暗模式的适配【Android 10】

https://developer.android.google.cn/guide/topics/ui/look-and-feel/darktheme

实现

首先在style.mxl主题继承DayNight主题,我们的就有了适配黑夜主题的能力

在这里插入图片描述

既然有了夜间模式主题,那接下来就要针对夜间模式做出适配,表现在字体和背景等方面,这些都和value.xml中的值有关,为了适配黑夜模式,我们要将values文件夹复制一份另存为values-night,成功之后AS的values文件夹下会有普通和night两个选项,我们就可以对这两个文件夹里的xml进行编辑进行不同模式的适配看了。

在这里插入图片描述 在这里插入图片描述

在我们需要适配的xml中,需要分别在values和values-night设定不同的值,而且名字要一样,否则会报错,这里改变了之前看起来不自然的主菜单为例,现在不能将android:xxxColor直接硬编码为"#XXXXX"(颜色代码)了,需要正确改为"@color/xxxxx",因为硬编码是不会被适配的,例如:

lv_index_unit.xml
<?xml version="1.0" encoding="utf-8"?>

<androidx.constraintlayout.widget.ConstraintLayout 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=“100dp”

android:background=“@color/colorUnitBackground”>

<TextView

android:id=“@+id/tv_tag”

android:layout_width=“80dp”

android:layout_height=“15dp”

android:layout_marginBottom=“10dp”

android:gravity=“center”

android:text=“@string/tv_tag”

android:textSize=“12sp”

android:textStyle=“italic”

app:layout_constraintBottom_toBottomOf=“parent”

app:layout_constraintEnd_toStartOf=“@+id/tv_text”

app:layout_constraintStart_toStartOf=“parent” />

<TextView

android:id=“@+id/tv_title”

android:layout_width=“230dp”

android:layout_height=“30dp”

android:layout_marginTop=“10dp”

android:gravity=“start”

android:orientation=“horizontal”

android:text=“@string/tv_title”

android:textColor=“@color/colorUnitTitle”

android:textSize=“22sp”

android:textStyle=“bold”

app:layout_constraintStart_toStartOf=“@+id/tv_text”

app:layout_constraintTop_toTopOf=“parent” />

<TextView

android:id=“@+id/tv_text”

android:layout_width=“190dp”

android:layout_height=“40dp”

android:layout_marginStart=“10dp”

android:layout_marginTop=“5dp”

android:gravity=“start”

android:text=“@string/tv_text”

android:textColor=“@color/colorUnitText”

android:textSize=“12sp”

app:layout_constraintStart_toEndOf=“@+id/iv_icon”

app:layout_constraintTop_toBottomOf=“@+id/tv_title” />

<TextView

android:id=“@+id/tv_time”

android:layout_width=“100dp”

android:layout_height=“15dp”

android:layout_marginEnd=“10dp”

android:layout_marginBottom=“20dp”

android:gravity=“end|center_vertical”

android:text=“@string/tv_time”

android:textSize=“12sp”

android:textStyle=“italic”

app:layout_constraintBottom_toBottomOf=“parent”

app:layout_constraintEnd_toEndOf=“parent” />

<ImageView

android:id=“@+id/iv_remove”

android:layout_width=“35dp”

android:layout_height=“35dp”

android:layout_marginEnd=“30dp”

android:layout_marginBottom=“10dp”

android:contentDescription=“@string/iv_remove”

app:layout_constraintBottom_toTopOf=“@+id/tv_time”

app:layout_constraintEnd_toEndOf=“parent”

app:srcCompat=“@drawable/icon_delete” />

<ImageView

android:id=“@+id/iv_icon”

android:layout_width=“60dp”

android:layout_height=“60dp”

android:layout_marginStart=“15dp”

android:layout_marginTop=“10dp”

android:contentDescription=“@string/iv_remove”

app:layout_constraintStart_toStartOf=“parent”

app:layout_constraintTop_toTopOf=“parent”

app:srcCompat=“@drawable/icon_notepad” />

<TextView

android:id=“@+id/tv_id”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:textColor=“#00FF0000”

app:layout_constraintStart_toStartOf=“parent”

app:layout_constraintTop_toTopOf=“parent” />

</androidx.constraintlayout.widget.ConstraintLayout>

activity_notepad.xml
<?xml version="1.0" encoding="utf-8"?>

<androidx.constraintlayout.widget.ConstraintLayout 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:fitsSystemWindows=“true”

tools:context=“.ActivityNotepad”>

<ScrollView

android:id=“@+id/sv”

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:background=“#FFFFFF”

app:layout_constraintBottom_toBottomOf=“parent”

app:layout_constraintEnd_toEndOf=“parent”

app:layout_constraintHorizontal_bias=“0.0”

app:layout_constraintStart_toStartOf=“parent”

app:layout_constraintTop_toTopOf=“parent”

app:layout_constraintVertical_bias=“0.0”>

<LinearLayout

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数初中级安卓工程师,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年最新Android移动开发全套学习资料》送给大家,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
img
img
img
img

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频
如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注Android)
img

总结

算法知识点繁多,企业考察的题目千变万化,面对越来越近的“金九银十”,我给大家准备好了一套比较完善的学习方法,希望能帮助大家在有限的时间里尽可能系统快速的恶补算法,通过高效的学习来提高大家面试中算法模块的通过率。

这一套学习资料既有文字档也有视频,里面不仅仅有关键知识点的整理,还有案例的算法相关部分的讲解,可以帮助大家更好更全面的进行学习,二者搭配起来学习效果会更好。

部分资料展示:




有了这套学习资料,坚持刷题一周,你就会发现自己的算法知识体系有明显的完善,离大厂Offer的距离更加近。

资料获取方法:点赞+关注+转发,然后进入我的【GitHub】,里面有免费获取途径

…(img-QqXtCGAT-1710511232021)]
[外链图片转存中…(img-EqHtjXMr-1710511232021)]
[外链图片转存中…(img-RTLw239n-1710511232022)]
[外链图片转存中…(img-Fnx6Pq4I-1710511232022)]

有了这套学习资料,坚持刷题一周,你就会发现自己的算法知识体系有明显的完善,离大厂Offer的距离更加近。

资料获取方法:点赞+关注+转发,然后进入我的【GitHub】,里面有免费获取途径

  • 25
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值