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
window.
• 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 R.style 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
"@android:style/Theme.NoTitleBar".
Dialogs
• A dialog is a small window that prompts the user
to make a decision or enter additional
information.

• 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
interruptive.
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.


android:theme="@style/Theme.AppCompat.Dialog“
3. Compare your DialogActivity.java file to this:
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
public class DialogActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dialog);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action",
Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
} });
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action b
getMenuInflater().inflate(R.menu.menu_dialog, menu);
return true;
}
@Override
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 == R.id.action_settings) {
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 MainActivity.java file:
package com.jfdimarzio.activity101;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.CountDownTimer;
import android.os.Bundle;
public class MainActivity extends Activity {
ProgressDialog progressDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onStart()
{
super.onStart();
progressDialog = ProgressDialog.show(this,"Please Wait",
"Processing...",true);
CountDownTimer timer = new CountDownTimer(3000,1000) {
@Override
public void onTick(long millisUntilFinished) {
}
@Override
public void onFinish() {
progressDialog.dismiss();
}
}.start();
}}
Press Shift+F9 to debug the application on the Android emulator. You see the progress
dialog.