マテリアルな AppCompat テーマの作成のひな

AppCompat のテーマ を使ったカラーリングは,

正直,

どのSDKバージョンで,

どのアイテムが,

どこに反映されるか

謎ですね?

実際,

実機で,

各バージョンで,

それぞれ確認してますね?

こんなかんじだそうですが...

AndroidのAppCompat Themeの継承関係がよくわからないので図にしてみた - Qiita

今や継承すぎですね.

以下で分かりやすくまとめられています.

MoshDev/ThemesAndStyles: A sample application demonstrate Android themes and styles capabilities


<style name="MaterialTheme" parent="Theme.AppCompat.Light">

    <!-- 1 -->
    <item name="colorPrimaryDark">#5c142a</item>

    <!-- 2 -->
    <item name="colorPrimary">#8B1E3F</item>

    <item name="colorAccent">#3C153B</item>

    <!-- 3. CheckBox, RadioButton, (SeekBar, ProgressBar with alpha)  & Inactive EditText underline-->
    <item name="android:colorControlNormal">#89BD9E</item>

    <!-- 4. Used with Active -> SeekBars, ProgressBars, Switches, Checkboxes and RadioButtons & Active EditText underline-->
    <item name="android:colorControlActivated">#006665</item>

    <!-- 5. Used with Buttons-->
    <item name="android:colorButtonNormal">#EB7BC0</item>

    <!-- 6. Used with Buttons & EditText text & Toolbar title-->
    <item name="android:textColorPrimary">#04dc00</item>

    <!-- 7. TextAppearance Medium-->
    <item name="android:textColorSecondary">#00f</item>

    <!-- 8. CompoundButton text-->
    <item name="android:textColorPrimaryDisableOnly">#F00</item>

    <!-- 9. Normal and TextAppearance Small TextView-->
    <item name="android:textColorTertiary">#FF934F</item>

    <!-- 10. EditText Hint text color-->
    <item name="android:textColorHint">#6f00ff</item>

    <!-- 11 -->
    <item name="android:windowBackground">@color/windowBackground</item>

    <!--Activating/Enabling Ripple Effect-->
    <item name="android:colorControlHighlight">#F0C987</item>

    <!--Defaults-->
    <!--<item name="colorControlNormal">?android:attr/textColorSecondary</item>-->
    <!--<item name="colorControlActivated">?attr/colorAccent</item>-->
    <!--<item name="colorControlHighlight">@color/ripple_material_light</item>-->
    <!--<item name="colorButtonNormal">@color/button_material_light</item>-->
  </style>

ThemesAndStyles/styles.xml at master · MoshDev/ThemesAndStyles

こういう役に立つドキュメントが公式にない (のかあるのか分からない) のが一番の謎ですね.


Google Pixel で不具合連発の模様

購入しようと思ってました.

Google Pixel

が, しかし,

ここ数日で, 不具合ネタが連発されています.

「バッテリー残量30%で勝手にシャットダウン」

Some Pixel phones would prematurely shut down at or around 30 percent and would not turn back on until a charger is connected.

Some Google Pixel devices shutting down at 30% battery | AndroidAuthority

Reddit: Some Google Pixel devices shutting down at 30% battery : Android

「スピーカー音声に雑音が入る」

According to a considerable amount of Pixel and Pixel XL users, their phones suffer from a static distortion when the volume is at the three highest levels.

Google Pixel phones may have an audio problem | AndroidAuthority

If you own a Pixel or Pixel XL do you... - Results - Straw Poll

PSA - Currently on my 4th Pixel XL replacement due to an audio issue that appears to affect all Pixels (Video in description) and has not been acknowledged by Google : Android

どちらも, 投稿数や内容から見て事実っぽいし, 以前のNexusシリーズからの不具合を引きずってきているようにも見えます.

Some Nexus 6P devices are affected by bootloop issues

こんなコメントがありました.

I really feel like we are in the age of version release hell.

私たちユーザーもいろいろ考え直す時期なのかも知れません.

まあ, ぶっちゃけると, ポチってから気がついたのですがね...

日本で使える LTE/3G バンド は?


AppCompat 25.1.0 では効かない Android 4.4.x の backgroundTint

最初の私のイメージとしては,

サポートライブラリが充実してきているので ボタンの色は, banckgroundTint で簡単に変更できる!

でしたが...

おさらい

まず, ボタンを設置します.


    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="@android:color/white"
        android:text="Button" />

灰色のボタンが表示されて押したら, それなりにエフェクトが効いて「押されました感」が見て分かります.

ボタンの色を変えます.


    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="@android:color/white"
        android:text="Button"
        android:background="@color/colorAccent" />

ボタンの色が変わりましたが, 押したときにエフェクトが効きません.

background 属性のかわりに backgroudTint を使います.


    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="@android:color/white"
        android:text="Button"
        android:backgroundTint="@color/colorAccent" />

これで, 背景色も変わりかつエフェクトも効きます.

background ではなく, backgroundTint で色を指定する

ということですね.

Button と AppCompatButton の記述

StackOverflow などを見ているとさまざまな記述が見えます.

android - Lollipop's backgroundTint has no effect on a Button - Stack Overflow

ただ「ボタンの色を変えたいだけ」なのですが, なんだか混乱しています.

backgroudTint を使った記述にも似たようなものいくつかあるようです.


    <android.support.v7.widget.AppCompatButton
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="@android:color/white"
        android:text="AppCompatButton"
        android:backgroundTint="@color/colorAccent" />


    <android.support.v7.widget.AppCompatButton
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="@android:color/white"
        android:text="AppCompatButton"
        app:backgroundTint="@color/colorAccent" />

Button のかわりに AppCompatButton を使っていたり, backgroundTint の prefix が android: となっていたり app: になっています.

とりあえず, すべてをレイアウトに記述して表示してみました.

以下3つの挙動は予想通りで同じです.


<Button
    android:backgroundTint="@color/colorAccent"
    ...


<AppCompatButton
    android:backgroundTint="@color/colorAccent"
    ...


<AppCompatButton
    app:backgroundTint="@color/colorAccent"
    ...

Button と記述した場合でも, 内部でいい感じに入れ替えてくれているようですね.

[Tool]-[Android]-[Layout Inspector]

AppCompat を意識すること無く, 昔からの Button を使って記述していけばサポートライブラリが対応してくれるということですね!

AppCompat は えらい!!

Android 4.4 KITKAT で確認する

結果 : 全てダメ.

え,

色とエフェクト両方きちんと反映されているものがない...

なんなんすかね これ...

AppCompat のバージョンを下げてみます.

//compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:appcompat-v7:25.0.1'

Android 4.4 では, backgroudTint が ひとつの記述だけしか意図通りに表示してくれません.

AppCompat はクソ!!

そら混乱もしますわ.

まとめ

backgroundTint についての
OSバージョンと appcompat-v7 バージョンの関係

現状では,

AppCompat-v7 を 25.0.1 で


   <android.support.v7.widget.AppCompatButton
	....
        app:backgroundTint="@color/colorAccent" />

と書いておくのが吉.