T
T
TopazaPella2020-02-16 17:09:11
android studio
TopazaPella, 2020-02-16 17:09:11

How to change color and content in Toolbar?

Hello. Do not judge for a stupid question, I recently started to understand Android Studio and, in fact, Java. It seems that I do everything as they say, but a stone flower does not come out.
I add a toolbar, it is gray, although others are written in the topic (colorPrimary works in other places). And it says "android... Toolbar". If I understand correctly, should be the name of the application? In short, I can't add anything inside and I can't change the color. Why? I am sure that the answer is somehow very simple, somewhere I wrote something wrong, but I just can’t understand where. Help me please.

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.eremeeva.dietcalculator" >

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        tools:ignore="GoogleAppIndexingWarning">

        <activity android:name=".MainActivity" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>

</manifest>


toolbar.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/my_toolbar"
    android:minHeight="?attr/actionBarSize"
    android:background="@color/colorPrimary" />


styles.xml
<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>



</resources>


colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#8F00AD</color>
    <color name="colorPrimaryDark">#8F00AD</color>
    <color name="colorAccent">#D81B60</color>
</resources>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
TopazaPella, 2020-02-18
@TopazaPella

Ha, this question in Yasha is in 3rd place on the request "android studio how to connect your toolbar", but the problem has not been solved (((
UPD:
In general, it's about the dependencies and the package from which it was necessary to import the tublar. The
answer to this question

Respectively import toolbar from the package:
androidx.appcompat.widget.Toolbar

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question