How to use Resources in Android Application.
Previous lesson we learnt how to implement Button onClick Method. Today we are going to learn how to use application resources.
Every android application has resources.These resources include string variables,images.Think of a situation where you are depending application that can be used in different locations,different countries.You will be required to write string resources in different languages.
Once the resources have been declared in the application,its easy to use them.Am going to demostrate how to use string variables and images in your application.
For Example Below code gets string resource from string xml file.
[
Now let get Image resource.See below code.
[
Every android application has resources.These resources include string variables,images.Think of a situation where you are depending application that can be used in different locations,different countries.You will be required to write string resources in different languages.
Once the resources have been declared in the application,its easy to use them.Am going to demostrate how to use string variables and images in your application.
For Example Below code gets string resource from string xml file.
[
// Get a string resource from your app's Resources
String hello = getResources().getString(R.string.hello_world); // Or supply a string resource to a method that requires a string
TextView textView = new TextView(this); textView.setText(R.string.hello_world);]
Now let get Image resource.See below code.
[
<ImageViewandroid:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/country_flag" />]