Skip to main content

Posts

Showing posts from November, 2019

Applying Styles and Themes to an Activity

By default , an activity is themed to the default Android theme. However , there been a push in recent year to adopt a new theme known as Material . The Material theme has a much more modern and clean look to it. There are two versions of the Material theme available to Android developers : Material Light and Material Dark , Either of these themes can be applied from the AndroidManifest.xml To apply one of the Material themes to an activity , simply modify the <Application> element in the AndroidManifest.xml file by changing the default android:theme attribute. (Please be sure to change all instances of "com.android" to whatever package name your project is using.) <?xml version="1.0" encoding="utf-8"?> <manifest xmls:android="http://schemas.android.com/apk/res/android"        xmlns:tools="http://schemas.android.com/tools"        package="com.android.activity101">        <application          

Understanding the Life Cycle of a Activity

1. Using Android Studio , create a new Android project and name is Activity101. 2. In the Activity101Activity.java file , add the following highlighted statements. Package com.example.activity101; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; public class MainActivity extends AppCompatActivity {        String tag="LifeCycle Step";       @Override        protected void onCreate(Bundle savedInstanceState)        {                super.onCreate(savedInstanceState);                setContentView(R.layout.activity_main);                Log.d(tag,msg:"In the onCreate () event");        }        public void onStart()        {                 super.onStart();                 Log.d(tag,msg:"In the onStart () event");        }        public void onRestart()        {                 super.onRestart();                 Log.d(tag,msg:"In the onRestart () event");        }   

Understanding Activities

This blog begins by showing you to create an activity. To create an activity , you create a Java class that extends the Activity base class : public class MainActivity extends AppcompatActivity {           @Override           protected void onCreate(Bundle savedInstanceState)           {                     super.onCreate(savedInstanceState);                     setContentView(R.laout.activity_main);           } } Your activity class loads its user interface ( UI ) component using the XML file defined in your res/layout folder . In this example , you would load the UI from the main.xml file :           setContentView(R.layout.activity_main); Every activity you have in your application must be declared in your AndroidManifest.xml file , like this : <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android package="com.jfdimarzio.hellworld">            <application