Unit2-2


テーマ


color.xmlで色、トピックを定義します.xmlでコードを変更すると、アプリケーションのメイントピックの色を変更できます.
https://material.io/resources/color/#!/?view.left=0&view.right=0
上記のサイトは色決定に使用できます.

構築アイコン


resフォルダを右クリックして、アプリケーションの構築アイコンを設定します.
Foreground LayerとBackground Layerでは、xmlファイルのパスを再設定することで、必要なアイコンに置き換えることができます.

現実的


https://material.io/components
上のリンクには、アンドロイドの通常uiコンポーネントが表示されます.これらのメタコンポーネントを使用すると、ユーザーはアプリケーションのuiをより簡単に使用できます.
dependencies {
    ...
    implementation 'com.google.android.material:material:<version>'
}
これを使用するには、プロジェクトの依存項目として「機械設計コンポーネント」(MDC)ライブラリを使用する必要があります.通常、build.gradleに含まれます.
<com.google.android.material.textfield.TextInputLayout
   android:id="@+id/cost_of_service"
   android:layout_width="160dp"
   android:layout_height="wrap_content"
   android:hint="@string/cost_of_service"
   app:layout_constraintStart_toStartOf="parent"
   app:layout_constraintTop_toTopOf="parent">

   <com.google.android.material.textfield.TextInputEditText
       android:layout_width="match_parent"
       android:layout_height="wrap_content"/>

</com.google.android.material.textfield.TextInputLayout>
たとえば、MDCライブラリを含むTextInputEditTextのTextInputLayoutを使用する場合は、xmlファイルに上記の内容を記述する必要があります.
<item name="textInputStyle">@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox</item>
<item name="radioButtonStyle">@style/Widget.TipTime.CompoundButton.RadioButton</item>
<item name="switchStyle">@style/Widget.TipTime.CompoundButton.Switch</item>
textInputLayoutでは、上記のコードをtheme.xmlに追加し、「機械設計ガイド」で提案された入力ボックスのようにします.

アイコン


アプリケーションのアイコンでは、複数のバージョンのビットマップ画像を提供するよりも、ベクトルラベルを使用します.ベクトルloubleは、画像を構成する実際のピクセルを格納するのではなく、画像の作成方法に関する説明を格納するXMLファイルとして表されます.
<ImageView
        android:id="@+id/icon_service_question"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:srcCompat="@drawable/ic_service"
        ...
          />
リソースマネージャ-vector assetをクリックして適切なクリップを追加することで、xmlファイルで上記の内容を使用できます.

スタイル


スタイルは、単一の部品タイプのビュー属性値のセットです.たとえば、TextViewスタイルでは、フォント色、フォントサイズ、背景色などを指定できます.resフォルダにstyle.xmlを作成し、フォント、サイズなどを指定することで、レイアウト内のすべてのuiに適用できます.
<style name="Widget.TipTime.TextView" parent="Widget.MaterialComponents.TextView">
    <item name="android:minHeight">48dp</item>
    <item name="android:gravity">center_vertical</item>
    <item name="android:textAppearance">?attr/textAppearanceBody1</item>
</style>
<TextView
    android:id="@+id/service_question"
    style="@style/Widget.TipTime.TextView"
    ... />
テキストビュースタイルを指定することで、アプリケーション内のすべてのtextviewの設計を簡単に定義できます.?attr/textAppearanceBody1からtextAppearanceまではシルクで提供されるプレハブスタイルと考えられる.

Espresso



Espressoは計量試験の基本単位である.Android Test>パッケージ名>テストクラスでテストを作成できます.(ない場合は作成)
@RunWith(AndroidJUnit4::class) // 테스트 실행기 지정
class CalculatorTests {

    @get:Rule()
    val activity = ActivityScenarioRule(MainActivity::class.java)

    @Test
    fun calculate_20_percent_tip() {
        //cost_of_service_edit_text를 찾아서 숫자 입력
        onView(withId(R.id.cost_of_service_edit_text))
            .perform(typeText("50.00"))
        //버튼 찾아서 클릭
        onView(withId(R.id.calculate_button)).perform(scrollTo()).perform(click())
        //예상 값과 일치하는지 확인
        onView(withId(R.id.tip_result))
            .check(matches(withText(containsString("10.00"))))
    }
}
使用例は次のとおりです.ボタンやテキストフィールドなどのuiを検索して値を入力したり、正しい値が含まれているかどうかを確認したりできます.
テストを実行して、シミュレータは自分で実行して、自分で値をプラスしてテストを行います