I am facing a problem to show images and TextView in Custom Toolbar. I have this Layout structure.
RelativeLayout -> androidx.appcompat.widget.Toolbar -> LinearLayout(horizontal) -> ImageView,TextView.
Also, I got built-In ActionBar in project and i used
getSupportActionBar().hide();
``` to remove it.
here is the complete XML code.
I have checked on both virtual and physical device but images and text of toolbar not showing.
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:background="@color/white"
android:elevation="6dp"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme"
tools:ignore="UnusedAttribute">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
tools:ignore="UselessLeaf">
<ImageView
android:id="@+id/imageView8"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="10dp"
android:foreground="@drawable/camera"
android:contentDescription="@string/todo1" />
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_weight="1"
android:fontFamily="@font/bilbo_swash_caps"
android:gravity="center_vertical"
android:text="@string/instagram"
android:textColor="@color/textcolor"
android:textSize="25sp"
android:textStyle="bold"
tools:ignore="InefficientWeight,TextSizeCheck" />
<ImageView
android:id="@+id/imageView7"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="10dp"
android:contentDescription="@string/todo2"
app:srcCompat="@drawable/instatv" />
<ImageView
android:id="@+id/imageView6"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:contentDescription="@string/todo"
android:tint="@color/textcolor"
app:srcCompat="@drawable/send"
tools:ignore="UseAppTint" />
</LinearLayout>
</androidx.appcompat.widget.Toolbar>
```
I have used
android:src
app:srcCompat
android:foreground
android:background
I have also change the colors to see the difference but even changing the color in toolbar is not working.
It is the values\themes.xml code
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.App" parent="Theme.MaterialComponents.DayNight.NoActionBar.Bridge">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_700</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="21">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
-->
</style>
And it is the night\themes.xml code
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.App" parent="Theme.MaterialComponents.DayNight.NoActionBar.Bridge">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_200</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/black</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_200</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="21">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
That is the message I got as a warning for Toolbar. And for that reason when I was trying to do anything with the toolbar it was not effected.
This check finds attributes set in XML files that were introduced in a version newer than the oldest version targeted by your application (with the minSdkVersion attribute). This is not an error; the application will simply ignore the attribute. However, if the attribute is important to the appearance or functionality of your application, you should consider finding an alternative way to achieve the same result with only available attributes, and then you can optionally create a copy of the layout in a layout-vNN folder which will be used on API NN or higher where you can take advantage of the newer attribute. Note: This check does not only apply to attributes. For example, some tags can be unused too, such as the new element in layouts introduced in API 21.