Colors in the Android Studio



 This post continues from

https://varanasisoftwarejunction.blogspot.com/2021/01/changing-properties-in-android-app.html

To start with we will open first fragment.xml and colors.xml

Varanasi Software Junction: Layout and Colors.xml

Next step define a new color. We will call it textbgcolor


<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="purple_200">#FFBB86FC</color>
    <color name="purple_500">#FF6200EE</color>
    <color name="purple_700">#FF3700B3</color>
    <color name="teal_200">#FF03DAC5</color>
    <color name="teal_700">#FF018786</color>
    <color name="black">#FF000000</color>
    <color name="white">#FFFFFFFF</color>
    <color name="textbgcolor">#00FFFF</color>
</resources>

We will also define a gradient color and place it in the drawables.

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient android:startColor="#FF0000"
        android:centerColor="#00FFFF"
        android:endColor="#00FF00"
        android:angle="-90" />
</shape>




Write it in the first_fragment.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=".FirstFragment"
android:background="@drawable/layoutbackground"
>

    <TextView

        android:background="@color/textbgcolor"
        android:id="@+id/textview_first"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_first_fragment"
        app:layout_constraintBottom_toTopOf="@id/button_first"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/button_first"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/next"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/textview_first" />
</androidx.constraintlayout.widget.ConstraintLayout>



Look up the files in Android Studio

Varanasi Software Junction: Android Studio Layout and Colors


Open fragment_first.xml and choose split view

Varanasi Software Junction: Android Studio Layout and Colors


Look up the options in the view.

Varanasi Software Junction: Android Studio Layout and Colors


Experiment with the other options as well.

Post a Comment

0 Comments

Me