Adding colors to your project for later use

  1. In your project panel double click on res > values > colors.xml to open your color resources file

  2. Copy and paste the following code into your project this will allow you to change colors of different aspects of your project

<resources>

<color name="colorPrimary">#10141C</color>

<color name="colorPrimaryDark">#171C26</color>

<color name="colorAccent">#4e33ff</color>

</resources>

  • In your Project panel double click: res > layout > fragment_fist.xml

  • You will notice your app will appear on the top right of your app you should see

"Code, Split, Design" click on Split

  • To change the background color add a line under tools:context that looks like this android:background="@color/colorPrimaryDark"> the entire beginning should look like this:

<?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="@color/colorPrimaryDark">

You can use these for any code block background or TextColor:

  • The beginning of your code defines the default app layout

    • Textview: Adds a label to your project you can use for your app title or details

    • EditText: Allows you to insert a textbox for your users

    • Button: Adds an interactive button to perform tasks

    • ImageView: Allows you to inset an image into your app