Skip to main content

AMP PRACTICAL 2

 

Aim: Android Resources: (Color, Theme, String, Drawable).



Colors.xml

 

<?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>
 

</resources>




To apply color to Textview :


Using code


<TextView

android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@color/black" android:text="HelloWorld!" 

android:textColor="#FEFEFE"

app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" />


or using attributes window




Note that we can apply only those colors which are stored in Colors.xml file





Dimensions



Theme:

Style.xml

<resources>

<!-- Base application theme. -->

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

<!-- Customize your theme here. -->

 <item name="colorPrimary">@color/colorPrimary</item>

<item name="colorPrimaryDark">@color/colorPrimaryDark</item>

 <item name="colorAccent">@color/colorAccent</item>

</style>

</resources>







String.xml:

<resources>

<string name="app_name">My Application</string>

 <string name="hello">Hello World!!!</string>

 <string name="college"> TILAK COLLEGE </string>

 <string name="contact">7058332304</string>

 </resources>

 

Using code

<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/college"

app:layout_constraintBottom_toBottomOf="parent" android:textColor="@color/deeppink" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" />


Output




Drawable:

1.  Right click on drawable folder



1.  Copy the image if you want to create image drawable

 2.   Paste that image file inside the drawable folder



Now to apply image to background of activity -à select activity -à attributes -à backgroundàname of      image







Comments