UI Flashcards

1
Q

When is the R class generated?

A

Build time

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the units of measure for dimensions and their purposes? (6)

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the syntax for creating a Toast?

What is the syntax for creating a Snackbar?

A

Toast.makeText(context, message, duration ).show( )
context - usually this
message - String to be displayed
duration - Toast.LENGTH_*

Snackbar.make(contextView, string, duration).show()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Using the Layout Editor (Design tab) how do you add a new font?

A
  • 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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How to re use the properties of a styled component?

A

Right click > Extract style

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do you hide the keyboard?

How do you show the keyboard?

A

=== 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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

If a view isn’t getting the focus when needed, what method could be used?

A

View.requestFocus( )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you apply a chainstyle?

What are the different types of chainstyle?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How to add a baseline constraint?

A

app:layout_constraintBaseline_toBaselineOf=”@id/view”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What can a ^merge^ tag be used for in a layout xml?

A

Eliminate redundant layouts.

An example of a redundant layout would be ConstraintLayout > LinearLayout > TextView, where the system might be able to eliminate the LinearLayout.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What does CDATA enable?

What is the syntax for using CDATA?

A

HTML formatting in String resources.

^string name=”title”^^![CDATA[^h3^My String As Header^/h3^]]^^/string^

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

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?

A

API 17

To support RTL flow

When targetting API 16 or lower, use both start/end AND left/right

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the precedence of styling being applied?

A

View

Style

Default Style
- provided by Android

Theme

  • properties consistent throughout the app
  • fonts, colours, etc

TextAppearance

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

When adding a font to a theme, what are the names of the two attributes that need to be added?

A

android: fontFamily

fontFamily

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Style attributes override Theme attributes, so in a TextView how do you make the Theme’s styling take precedence?

A

android:textAppearance=”@style/TextAppearance.MyTheme”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the dependency for Material Components?

A

implementation ‘com.google.android.material:material:$version’

17
Q

how do you add a FAB to a Screen with a ScrollView containing a ConstraintLayout?

A
  1. Surround the ScrollView in a Coordinator Layout
  2. Change the ScrollView to NestedScrollView
  3. Add the FAB at the bottom of the CoordinatorLayout, just after the end of the NestedScrollView
  4. To start with, the FAB will need the following attributes to be set:
    - gravity
    - margin
    - drawable
    - onClick
18
Q
  1. At which url can you find Material typography templates?

2. What is the syntax for inheriting one of these templates in your style?

A
  1. material. io/develop/android/theming/typography
  2. ^style name=”TextAppearance.MyCustomisedText” parent=”TextAppearance.MaterialComponents.TemplateName”^
19
Q

What is the difference between a Theme and a ThemeOverlay?

A

Theme - global theme for the entire app

ThemeOverlay - overrides the app theme for specific views, especially the toolbar

20
Q

What is the syntax for applying a Dark Theme to a Toolbar?

A

^androidx.appcompat.widget.Toolbar
android:theme=”@style/ThemeOverlay.MaterialComponents.Dark.ActionBar”

android:background=”?attr/colorPrimaryDark”

21
Q

What is the colorOnPrimary attribute?

A

a color that meets accessibility guidelines for text or iconography when drawn on top of the primary color

colorOnSecondary does the same for text on the secondary color

22
Q

What is the url for the Material Components Color Tool?

A

material.io/tools/color/