1.打开一个新项目。
2.选择一个空的Activity项目模板。这将创建一个带有操作栏的空白屏幕。
3.输入项目的名称,然后语言选择Kotlin。
4.单击完成。
5.运行项目以查看初始应用程序的外观
运行效果如下:
要删除工具栏,导航栏,状态栏和文本并向背景添加颜色,请执行以下操作:
-
打开styles.xml
-
将基础主题的父级从_Theme.AppCompat.Light.DarkActionBar替换_为_Theme.AppCompat.Light.NoActionBar。_(如果您此时运行该应用程序,将会看到操作栏/工具栏消失了)
-
通过将_android:windowFullscreen_设置为true(隐藏状态栏)并将_android:background_设置为默认颜色,为您的应用添加新的自定义设置
4.打开_activity_main.xml_并从布局中删除TextView以删除“ Hello World!”文本。
5.现在,在_MainActivity.kt中_,添加以下行以隐藏系统导航栏(如果复制并粘贴这些行出现 Unresolved reference build errors,请单击未解决的对象,然后按Alt + Enter添加库):
override fun onWindowFocusChanged(hasFocus: Boolean) {
super.onWindowFocusChanged(hasFocus)
if (hasFocus) {
hideSystemUIAndNavigation(this)
}
}
private fun hideSystemUIAndNavigation(activity: Activity) {
val decorView: View = activity.window.decorView
decorView.systemUiVisibility =
(View.SYSTEM_UI_FLAG_IMMERSIVE
// Set the content to appear under the system bars so that the
// content doesn’t resize when the system bars hide and show.
or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN // Hide the nav bar and status bar
or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_FULLSCREEN)
}
6.运行该应用程序。
现在,您基本上会看到一个空屏幕,以默认颜色作为背景:
在开始动画之前,我们只需要设置一些样式即可:红色背景及福师大校徽。
首先开始:
-
打开colors.xml
-
将_colorPrimary_和_colorPrimaryDark_更改为的红色。
-
将福师大校徽复制到drawable文件夹下。
-
打开_activity_main.xml_,然后将校徽设置为宽度和高度都为128dp的ImageView。
<ImageView
android:layout_width=“128dp”
android:layout_height=“128dp”
android:src=“@drawable/fjnu”
app:layout_constraintTop_toTopOf=“parent”
app:layout_constraintStart_toStartOf=“parent”
app:layout_constraintEnd_toEndOf=“parent”
app:layout_constraintBottom_toBottomOf=“parent”
/>
5.运行该应用程序,然后查看新更改。
====================================================================
由于MotionLayout是ConstraintLayout的一部分,并且目前仅在v2.0中有效,因此要使用它,我们首先需要更新ConstraintLayout依赖项:
-
打开_build.gradle_ (Module)
-
在依赖项部分添加此行,或将您的_constraintlayout_依赖项替换为:
implementation ‘androidx.constraintlayout:constraintlayout:2.0.0-beta4’
为了最终使动画栩栩如生,您需要执行一些简单的步骤
-
打开_activity_main.xml。_
-
将activity_main.xml的布局设置为MotionLayout。
-
在xml目录下添加一个新的_activity_motion_scene.xml_。
-
_activity_motion_scene.xml_的设置的动画内容如下:
-
将校徽缩小,缩小的校徽停留0.5到1秒并逆时针旋转360度。
-
最后,将其放大以填满整个屏幕
<MotionScene
xmlns:android=“http://schemas.android.com/apk/res/android”
xmlns:motion=“http://schemas.android.com/apk/res-auto”>
<Transition
motion:constraintSetEnd=“@+id/end”
motion:constraintSetStart=“@id/start”
motion:duration=“1000”>
<KeyAttribute
motion:motionTarget=“@+id/imageView”
motion:framePosition=“0”
android:scaleX=“1.0” />
<KeyAttribute
motion:motionTarget=“@+id/imageView”
motion:framePosition=“0”
android:scaleY=“1.0” />
<KeyAttribute
motion:motionTarget=“@+id/imageView”
motion:framePosition=“20”
android:scaleX=“0.7” />
<KeyAttribute
motion:motionTarget=“@+id/imageView”
motion:framePosition=“20”
android:scaleY=“0.7” />
<KeyAttribute
motion:motionTarget=“@+id/imageView”
motion:framePosition=“20”
android:scaleX=“0.2” />
<KeyAttribute
motion:motionTarget=“@+id/imageView”
motion:framePosition=“20”
写在最后
由于本文罗列的知识点是根据我自身总结出来的,并且由于本人水平有限,无法全部提及,欢迎大神们能补充~
将来我会对上面的知识点一个一个深入学习,也希望有童鞋跟我一起学习,一起进阶。
提升架构认知不是一蹴而就的,它离不开刻意学习和思考。
**这里,笔者分享一份从架构哲学的层面来剖析的视频及资料分享给大家,**梳理了多年的架构经验,筹备近1个月最新录制的,相信这份视频能给你带来不一样的启发、收获。
最近还在整理并复习一些Android基础知识点,有问题希望大家够指出,谢谢。
希望读到这的您能转发分享和关注一下我,以后还会更新技术干货,谢谢您的支持!
转发+点赞+关注,第一时间获取最新知识点
Android架构师之路很漫长,一起共勉吧!
《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》,点击传送门,即可获取!
新录制的,相信这份视频能给你带来不一样的启发、收获。
[外链图片转存中…(img-a9kTvOUs-1714548423135)]
[外链图片转存中…(img-7hDs3APa-1714548423136)]
最近还在整理并复习一些Android基础知识点,有问题希望大家够指出,谢谢。
希望读到这的您能转发分享和关注一下我,以后还会更新技术干货,谢谢您的支持!
转发+点赞+关注,第一时间获取最新知识点
Android架构师之路很漫长,一起共勉吧!
《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》,点击传送门,即可获取!