Android Kotlin的基础知识

前言

今天学习的是Android的Kotlin的基础知识中的布局编辑器,对于Android开发者来说布局还是很重要的,他是一个App的门面。

布局

选择项目 Android 窗格,在app/res/layout 文件夹中,打开要使用的布局文件
Android Kotlin的基础知识_第1张图片
对应于图片中的activity_main.xml


    <TextView
        android:id="@+id/textViewId"
        style="@style/my_textview_style"
        android:textAlignment="center"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

  • 提取控件的样式

通过对应的属性进行设置就好了,在我们添加好了所有的属性之后,可以右击属性文件refactor-> style 进而提取一个文件到 style文件中

  • 提取数值包括dp,sp

    <TextView
        android:id="@+id/textViewId"
        android:padding="18dp"
        android:textAlignment="center"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

此处我们可以选中padding的那行 同时按住 alt + enter 将数值提取到 dimens文件中

  • 添加字体
 <TextView
        android:id="@+id/textViewId"
        android:fontFamily="@font/allerta"
        android:textAlignment="center"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

你可以通过fontFamily属性来为当前的控件设置字体 ,font是res下边的字体文件,内部存储的是 xxx.ttf 的字体文件

你可能感兴趣的:(Android基础知识,android,kotlin)