Skip to main content

Posts

Showing posts from January, 2020

Displaying a Dialog Window

There are times when you need to display a dialog window to get a confirmation from the user. In this case , you can override the onCreateDialog() protected method defined in the Activity base class to display a dialog window. The following Try It Out shows you how. 1. Using Android Studio , create a new Android project and name it Dialog. When presented with the option , name the main activity DialogActivity. 2.Add the following theme in bold to the AndroidMainfest.xml file. Be sure to change all instances of "com.android" to whatever package name your project is using. <?xml version="1.0" encoding="utd-8"?> <manifest xmlns:android"http://schemas.android.com/apk/res/android" package="com.android.dialog">      <application           android:allowBackup="true"           android:icon:="@mipmap/ic_launcher"           android:label="@String/app_name"           android:supportRtl=&quo

Hiding the Activity Title

You can also hide the title of an activity if desired ( Such as when you just want to display a status update to the user). To do so , use the requestWindowFeature() method and pass it the window .FEATURE_NO_TITLE constant, like This : import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.Window; public class MainActivity extends AppCompatActivity{            @Override            protected void onCreate ( Bundle savedInstanceState )            {                         super.onCreate (savedInstanceState );                         setContentView (R.layout.activity_main);                         requestWindowFeature(Window.FEATURE_NO_TITLE);             } } Now you need change the theme in the AndoirdManifest.xml to a theme that has no title bar. Be sure to change all instances of "com.android" to whatever.package name your project is using. package com.android.activity101; <?xml version="1.0" encoding=