0
0

【Android】ImegeViewで設定したアイコンの色を変える

Posted at

はじめに

今回記事にする内容はタイトルにある通りですが、記事を書くきっかけになったのは
Jetpack Composeで色々触っていて、Iconのカラーを変えるのは簡単にできたけど、それ以外だとどうやってやるんだろ?と思ったのがきっかけです。

実践

準備段階としてImageViewを3つおきます。当然このままではImageがそのまま表示されているだけです。
 <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <ImageView
            android:id="@+id/icon1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_plus" />

        <ImageView
            android:id="@+id/icon2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_plus" />

        <ImageView
            android:id="@+id/icon3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_plus" />
</LinearLayout>

スクリーンショット 2024-09-08 20.20.16.png

次に ColorFilterを用いてImageViewにカラーをつけます。スクリーンショット 2024-09-08 20.26.06.png

        binding.icon1.setColorFilter(resources.getColor(R.color.red))
        binding.icon2.setColorFilter(resources.getColor(R.color.blue))
        binding.icon3.setColorFilter(resources.getColor(R.color.yellow))

uploading...0

このようにImageViewにもカラーを設定することができます。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0