Pro Android with Kotlin


CHAPTER 9: User Interface


Download 5.42 Mb.
Pdf ko'rish
bet170/223
Sana04.11.2023
Hajmi5.42 Mb.
#1746807
1   ...   166   167   168   169   170   171   172   173   ...   223
Bog'liq
@de android telegram Pro Android with Kotlin Developing Modern Mobile

201
CHAPTER 9: User Interface
For all that I refer to the online documentation of recycler views. The code presented here, 
however, should give you a good starting point.
Figure 9-1. Recycler view
Styles and Themes
The predefined styles an Android app uses by default already give a good starting point for 
professional-looking apps. If, however, you want to apply your company’s style guidelines 
or otherwise create a visually outstanding app, creating your own styles is worth the effort. 
Even better, create your own theme, which is a collection of styles to be applied to groups of 
UI elements.
Styles and themes get created inside res/values/ as XML files. To make a new theme, you 
use or create a file called themes.xml and write something like the following:




202
CHAPTER 9: User Interface

@color/colorPrimaryDark


@color/colorAccent


#FF0000

22sp


Here are a couple of notes on that:

The parent attribute is important. It expresses that we want to create 
a theme overriding parts of the Theme.AppCompat theme from the 
compatibility library.

Because of the naming schema Theme + DOT + AppCompat, we can 
infer that the theme Theme.AppCompat inherits from theme Theme. This 
dot-induced inheritance could have more elements.

Instead of the parent Theme.AppCompat, we could use one of its 
subthemes. You can see a list of them; inside Android Studio click 
the AppCompat part and then press Ctrl+B. Android Studio will open 
a file with the list of all subthemes, for example Theme.AppCompat.
CompactMenu, Theme.AppCompat.Light, and more.

In the example, we see two methods to overwrite styles. Those with 
android: at the beginning refer to style settings as defined for UI 
elements the same way as if we want to set styles from inside a layout 
file. You find all of them in the online API documentation for all the 
views. Better, however, you use those without android: at the beginning 
because those refer to abstract style identifiers that actually make 
up a theme. You get a list of possible item names if inside the online 
documentation you search for R.styleable.Theme.

The styling system has become complex over the years. If you are brave 
and have some time, you can navigate through all the files in Android 
Studio by repeatedly pressing Ctrl+B on the parents.

@color/... refer to entries inside the res/values/colors.xml files. You 
should adopt that method and define new colors in your app module’s 
res/values/colors.xml file.

The values of  elements can refer to styles via @style/.... For 
example, use the item @style/Widget.
AppCompat.Button
. You can overwrite such items as well; just 
define your own styles in styles.xml and refer to them.



Download 5.42 Mb.

Do'stlaringiz bilan baham:
1   ...   166   167   168   169   170   171   172   173   ...   223




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling