You are on page 1of 12

Style Vs Theme

• A Style is a collection of properties that

specify the look and format for a view or
• A Theme is a style applied to an entire activity
or application, rather than an individual view.
Applying Styles &Themes
• A theme is nothing but an Android style applied to an entire Activity or
application, rather than an individual View.
• To set a theme for all the activities of your application, open
the AndroidManifest.xml file and edit the <application> tag to include
the android:theme attribute with the style name.
• <application android:theme="@style/CustomFontStyle">
• if you want a theme applied to just one Activity in your application, then
add the android:theme attribute to the <activity> tag only.
• <activity android:theme="@style/CustomFontStyle">
• There are number of default themes defined by Android which you can
use directly or inherit them using parent attribute as follows −
• <style name="CustomTheme" parent="android:Theme.Light"> ... </style>
Default Styles & Themes

• The Android platform provides a large collection of styles and

themes that you can use in your applications. You can find a
reference of all available styles in the class.
• To use the styles listed here, replace all underscores in the style
name with a period. For example, you can apply the
Theme_NoTitleBar theme with
• A dialog is a small window that prompts the user
to make a decision or enter additional

• A dialog does not fill the screen and is normally

used for modal events that require users to take
an action before they can proceed.

• Dialogs inform users about a specific task and

may contain critical information, require
decisions, or involve multiple tasks.
• Dialogs contain text and UI controls
• They retain focus until dismissed or a required action
has been taken.
• Use dialogs sparingly(limit) because they are
Some dialog types include:
• Alerts are urgent interruptions that inform about a
situation and require acknowledgement.
• Simple menus display options for list items,
whereas simple dialogs can provide details or actions
about a list item.
• Confirmation dialogs require users to explicitly confirm
a choice.
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.
•Displaying a Dialog Window Using an Activity
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 to the AndroidManifest.xml file.

3. Compare your file to this:
import android.os.Bundle;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
public class DialogActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
Toolbar toolbar = (Toolbar) findViewById(;
FloatingActionButton fab = (FloatingActionButton) findViewById(;
fab.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action",
.setAction("Action", null).show();
} });
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action b
getMenuInflater().inflate(, menu);
return true;
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == {
return true;
return super.onOptionsItemSelected(item);
}ar if it is present.

Press Shift+F9 to debug the application on the Android emulator. Click the button to
display the dialog.
displaying a Progress dialog
• One common UI feature in an Android device is the “Please wait” dialog that you
typically see when an application is performing a long-running task.

• For example, the application might be logging in to a server before the user is
allowed to use it, or it might be doing a calculation before displaying the result to
the user. In such cases, it is helpful to display a dialog, known as a progress dialog,
so that the user is kept in the loop.

• Android provides a ProgressDialog class you can call when you want to display a
running meter to the user. ProgressDialog is easy to call from an activity.

• Steps to create a progress dialog

• 1.create a project ,use the Material theme in the AndroidManifest.xml file.
• 2. Add the bolded statements from the following code to the file:
package com.jfdimarzio.activity101;
import android.os.CountDownTimer;
import android.os.Bundle;
public class MainActivity extends Activity {
ProgressDialog progressDialog;
protected void onCreate(Bundle savedInstanceState) {
public void onStart()
progressDialog =,"Please Wait",
CountDownTimer timer = new CountDownTimer(3000,1000) {
public void onTick(long millisUntilFinished) {
public void onFinish() {
Press Shift+F9 to debug the application on the Android emulator. You see the progress