UI Flashcards
When is the R class generated?
Build time
What are the units of measure for dimensions and their purposes? (6)
dp
density-independent pixels
Scales to device’s screen’s physical density
(use this for non-text dimens)
sp
scale-independent pixels
Scales to both device screen size and user’s font size preference
(use this for font size, line height)
pt
point
1/72 inch assuming a 72dpi screen
px
pixels
Not scalable, not recommended
mm
millimetres
in
inches
What is the syntax for creating a Toast?
What is the syntax for creating a Snackbar?
Toast.makeText(context, message, duration ).show( )
context - usually this
message - String to be displayed
duration - Toast.LENGTH_*
Snackbar.make(contextView, string, duration).show()
Using the Layout Editor (Design tab) how do you add a new font?
- Attributes > font family > drop-down > More Fonts
- Select font and preview
EITHER
a) ship font files as part of APK (increases app size; not recommended)
- Select “Add font to project” radio button
- Click OK
OR
b) download font at runtime if not already available on device
- Select the “Create downloadable font” radio button
- Add following to Manifest:
^meta-data android:name=”preloaded_fonts” android:resource=”@array/preloaded_fonts”/^
How to re use the properties of a styled component?
Right click > Extract style
How do you hide the keyboard?
How do you show the keyboard?
=== HIDE KEYBOARD===
val inputMethodManager = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
inputMethodManager.hideSoftInputFromWindow(view.windowToken, 0)
=== SHOW KEYBOARD===
val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.showSoftInput(editText, 0)
If a view isn’t getting the focus when needed, what method could be used?
View.requestFocus( )
How do you apply a chainstyle?
What are the different types of chainstyle?
Apply with:
app:layout_constraintHorizontal_chainStyle=”spread”
- spread
The default style. Views are evenly spread in the available space, after margins are accounted for. - spread inside
The first and the last views are attached to the parent on each end of the chain. The rest of the views are evenly spread in the available space. - packed
The views are packed together, after margins are accounted for. You can then adjust the position of the whole chain by changing the bias of the chain’s head view.
How to add a baseline constraint?
app:layout_constraintBaseline_toBaselineOf=”@id/view”
What can a ^merge^ tag be used for in a layout xml?
Eliminate redundant layouts.
An example of a redundant layout would be ConstraintLayout > LinearLayout > TextView, where the system might be able to eliminate the LinearLayout.
What does CDATA enable?
What is the syntax for using CDATA?
HTML formatting in String resources.
^string name=”title”^^![CDATA[^h3^My String As Header^/h3^]]^^/string^
When were start and end brought in to replace left and right?
Why were they brought in?
How to handle this when targeting APIs pre-change?
API 17
To support RTL flow
When targetting API 16 or lower, use both start/end AND left/right
What is the precedence of styling being applied?
View
Style
Default Style
- provided by Android
Theme
- properties consistent throughout the app
- fonts, colours, etc
TextAppearance
When adding a font to a theme, what are the names of the two attributes that need to be added?
android: fontFamily
fontFamily
Style attributes override Theme attributes, so in a TextView how do you make the Theme’s styling take precedence?
android:textAppearance=”@style/TextAppearance.MyTheme”