ツールバーのオーバーフロー・アイコンにカラーフィルタを設定することはできません

MacaronLover:

なぜKotlinは私が私のツールバーのオーバーフロー・アイコンにカラーフィルタを適用することはできませんか?

表現型「カラーフィルター」の「カラーフィルターは、」関数として呼び出すことはできません。関数「呼び出しは()」が見つかりません

ここでは、画像の説明を入力します。

XML

<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/my_toolbar"
    android:layout_width="match_parent"
    android:layout_height="?android:attr/actionBarSize"
    android:minHeight="?android:attr/actionBarSize"
    app:contentInsetStartWithNavigation="0dp"
    app:contentInsetStart="0dp">

    <LinearLayout
        android:id="@+id/toolbar_textLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:layout_marginStart="16dp"
        android:orientation="vertical">

        <TextView
            android:id="@+id/toolbar_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
          style="@android:style/TextAppearance.Material.Widget.ActionBar.Title"/>
    </LinearLayout>
</androidx.appcompat.widget.Toolbar>

Kotlin

    mToolbar.overflowIcon?.colorFilter(Color.RED, PorterDuff.Mode.SRC_ATOP)

    // 
    val myAttr = intArrayOf(R.attr.tintColor)
    val taAttr = this.theme.obtainStyledAttributes(myAttr)
    val colorAttr = taAttr.getColor(0, Color.BLACK)
CommonsWare:

TL; DR:変更colorFilter()しますsetColorFilter()


2つのがありますsetColorFilter()上の方法はDrawable

一つはかかりますColorFilterそれは、対応する一致するgetColorFilter()方法を。Kotlinは、構文的に等しいものとして、それらの扱いvarという名前をcolorFilterあなたが持っていたのであれば、ColorFilterオブジェクトを、あなたが書くことができます:

 mToolbar.overflowIcon?.colorFilter = myReallyCoolColorFilterNoReallyItAddsBlueTintToEverything

setColorFilter()の色と:コールは、あなたが指定している2つのパラメータを取りますPorterDuff.Modeしかし、その方法があるsetColorFilter()、ありませんcolorFilter()だから、どちらかに切り替えsetColorFilter()たり:

 mToolbar.overflowIcon?.colorFilter = BlendModeColorFilter(Color.RED, BlendMode.SRC_ATOP)

あなたが参照しようとしているのでcolorFilter、Kotlinはあなたが意味することを前提としてcolorFilterプロパティを、それが機能型ではなく、1つのように呼び出すことができません。

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=278022&siteId=1