Я создал пользовательский градиентный файл для рисования, который я хочу использовать в качестве фона Toolbar
, но не могу его применить.Он просто отображается как серый (см. Изображение).Я делаю что-то неправильно?Я просмотрел несколько сообщений, но пока у меня ничего не получалось.
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<Toolbar
android:id="@+id/home_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/home_toolbar_gradient"
android:elevation="4dp"
android:minHeight="70dp"
android:theme="@style/customToolbar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
<TextView
android:id="@+id/title_home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="@font/Montserrat-Bold"
android:gravity="center"
android:text="@string/home"
android:textAlignment="center"
android:textColor="@android:color/white" />
</Toolbar>
<!-- Using a view with a gradient to create a drop navbar_shadow effect for the navbar -->
<View
android:layout_width="match_parent"
android:layout_height="4dp"
android:layout_above="@id/bottom_nav_bar"
android:background="@drawable/navbar_shadow" />
<com.google.android.material.bottomnavigation.BottomNavigationView
app:labelVisibilityMode="labeled"
android:id="@+id/bottom_nav_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:itemBackground="@android:color/white"
app:itemIconTint="@drawable/nav_selected_item_color"
app:itemTextColor="@drawable/nav_selected_item_color"
app:menu="@menu/bottom_nav_bar">
</com.google.android.material.bottomnavigation.BottomNavigationView>
</RelativeLayout>
home_toolbar_gradient.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:type="linear"
android:startColor="@color/toolbar_starting_color"
android:endColor="@color/toolbar_ending_color"
android:angle="75" />
</shape>
styles.xml:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:fontFamily">@font/montserrat_medium</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<!-- Custom Rounded Dialog style -->
<style name="RoundedDialog" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:windowBackground">@drawable/rounded_corners</item>
</style>
<style name="customToolbar" parent="Theme.AppCompat.Light.NoActionBar" />
</resources>
в MainActivity.java:
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar homeToolbar = findViewById(R.id.home_toolbar);
setSupportActionBar(homeToolbar);
и в манифесте:
android:theme="@style/Theme.AppCompat.Light.DarkActionBar"