* Style your TextView - Extract the style
- A style is a collection of attributes that specify the appearance and format for a view. A style can include font color, font size, background color, padding, margin, and other common attributes.
- You can extract(추출) the name text view's formatting into a style and reuse the style for any number of views in your app. Reusing a style gives your app a consistent(일관된) look when you have multiple views. Using styles also allows you to keep these common attributes in one location.
- Right-click the TextView in the Component Tree and select Refactor > Extract Style.
- In the Extract Android Style dialog, clear the layout_width checkbox, the layout_height checkbox, and the textAlignment checkbox. These attributes are usually different for each view, so you don't want them to be part of the style.
- In the Style name field, enter NameStyle.
- Click OK.
- A style is also a resource, so the style is saved in the res/values/ folder in a styles.xml file. Open styles.xml and examine the generated code for the NameStyle style, which will look similar to this:
<style name="NameStyle">
<item name="android:layout_marginTop">@dimen/layout_margin</item>
<item name="android:fontFamily">@font/roboto</item>
<item name="android:paddingTop">@dimen/small_padding</item>
<item name="android:textColor">@android:color/black</item>
<item name="android:textSize">@dimen/text_size</item>
</style>
6. Open activity_main.xml and switch to the Text tab. Notice that the generated style is being used in the text view as style="@style/NameStyle"
출처: https://codelabs.developers.google.com/codelabs/kotlin-android-training-linear-layout/index.html#5
Android Kotlin Fundamentals 02.1: Linear layout using the Layout Editor
In the AboutMe app, you can showcase interesting facts about yourself, or you can customize the app for a friend, family member, or pet. This app displays a name, a DONE button, a star image, and some scrollable text.
codelabs.developers.google.com
'Android' 카테고리의 다른 글
[Android] Architecture Component - ViewModel + LiveData + DataBinding (0) | 2020.09.11 |
---|---|
[Android] 데이터 바인딩을 사용한 문자열 형식 지정 (0) | 2020.09.11 |
[Android] Understand API levels and compatibility (0) | 2020.08.21 |
[Android] Use a default image (0) | 2020.08.21 |
[Android] Find views efficiently (0) | 2020.08.21 |