Иконки в Toolbar не отображается
Иконки в toolbar не отображаются в design окне и эмуляторе (текст в toolbar отображается). Я перепробовала уже несколько способов создать Toolbar и ActionBar, но ни один способ не сработал. Остановилась на этом: java файл не меняла. activity_main.xml файл:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<include layout="@layout/toolbar" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
toolbar.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/teal_700">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="61dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="0dp"
android:padding="16dp">
<ImageView
android:id="@+id/left_icon"
android:layout_width="66dp"
android:layout_height="49dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="13dp"
android:layout_marginTop="13dp"
android:icon="@drawable/a" />
<TextView
android:id="@+id/txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_toEndOf="@id/left_icon"
android:text="lalalallallalalalla" />
<ImageView
android:id="@+id/right_icon"
android:layout_width="77dp"
android:layout_height="67dp"
android:layout_alignParentEnd="true"
android:layout_marginEnd="0dp"
android:icon="@drawable/ic_launcher_foreground" />
</RelativeLayout>
</RelativeLayout>
Ответы (1 шт):
Автор решения: AVRamones
→ Ссылка
Вместо этого:
android:icon="@drawable/ic_launcher_foreground"
Сделайте так:
android:src="@drawable/ic_launcher_foreground"
Есть мнение что icon только в манифесте используется, для ссылки на иконку приложения.