<activity android:name=".app.DialogActivity"
android:label="@string/activity_dialog"
- android:theme="@android:style/Theme.Dialog">
+ android:theme="@android:style/Theme.Holo.Dialog">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.SAMPLE_CODE" />
<!-- Demonstrates an activity with a dialog theme.
See corresponding Java code com.android.sdk.app.DialogActivity.java. -->
-<!-- This screen consists of a single text field that displays some text. -->
-<TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/text"
- android:layout_width="match_parent" android:layout_height="match_parent"
- android:gravity="center_vertical|center_horizontal"
- android:text="@string/dialog_activity_text"/>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent" android:layout_height="match_parent"
+ android:orientation="vertical"
+ android:padding="4dip" android:gravity="center_horizontal">
+ <TextView android:id="@+id/text"
+ android:layout_width="wrap_content" android:layout_height="wrap_content"
+ android:gravity="center_vertical|center_horizontal"
+ android:text="@string/dialog_activity_text"/>
+ <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content"
+ android:orientation="horizontal" android:paddingTop="4dip">
+ <Button android:id="@+id/add"
+ android:layout_width="wrap_content" android:layout_height="wrap_content"
+ android:text="@string/dialog_activity_add">
+ <requestFocus />
+ </Button>
+ <Button android:id="@+id/remove"
+ android:layout_width="wrap_content" android:layout_height="wrap_content"
+ android:text="@string/dialog_activity_remove">
+ </Button>
+ </LinearLayout>
+ <LinearLayout android:id="@+id/inner_content"
+ android:layout_width="wrap_content" android:layout_height="wrap_content"
+ android:orientation="horizontal" android:paddingTop="4dip">
+ </LinearLayout>
+</LinearLayout>
<!-- Demonstrates starting and stopping a local service.
See corresponding Java code com.android.sdk.app.LocalSerice.java. -->
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:padding="4dip"
- android:gravity="center_horizontal"
- android:layout_width="match_parent" android:layout_height="match_parent">
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical" android:padding="4dip"
+ android:gravity="center_horizontal"
+ android:layout_width="match_parent" android:layout_height="match_parent">
<TextView
android:layout_width="match_parent" android:layout_height="wrap_content"
<string name="activity_dialog">App/Activity/Dialog</string>
<string name="dialog_activity_text">Example of how you can use the
Theme.Dialog theme to make an activity that looks like a
- dialog.</string>
+ dialog. It also has lots of text to show how text wrapping (and
+ corresponding window size adjustment) can happen in a dialog.</string>
+ <string name="dialog_activity_add">Add content</string>
+ <string name="dialog_activity_remove">Remove content</string>
<string name="activity_custom_dialog">App/Activity/Custom Dialog</string>
<string name="custom_dialog_activity_text">Example of how you can use a
custom Theme.Dialog theme to make an activity that looks like a
<!-- app/dialog examples strings -->
<!-- ============================== -->
- <string name="activity_alert_dialog">App/Dialog</string>
+ <string name="activity_alert_dialog">App/Alert Dialogs</string>
<string name="alert_dialog_two_buttons">OK Cancel dialog with a message</string>
<string name="alert_dialog_two_buttons2">OK Cancel dialog with a long message</string>
<string name="alert_dialog_two_buttons2ultra">OK Cancel dialog with ultra long message</string>
// Need the following import to get access to the app resources, since this
// class is in a sub-package.
import android.app.Activity;
+import android.content.Intent;
import android.os.Bundle;
+import android.view.View;
import android.view.Window;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
import com.example.android.apis.R;
+import com.example.android.apis.app.ForegroundService.Controller;
/**
* <h3>Dialog Activity</h3>
getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON,
android.R.drawable.ic_dialog_alert);
+
+ Button button = (Button)findViewById(R.id.add);
+ button.setOnClickListener(mAddContentListener);
+ button = (Button)findViewById(R.id.remove);
+ button.setOnClickListener(mRemoveContentListener);
}
+
+ private OnClickListener mAddContentListener = new OnClickListener() {
+ public void onClick(View v) {
+ LinearLayout layout = (LinearLayout)findViewById(R.id.inner_content);
+ ImageView iv = new ImageView(DialogActivity.this);
+ iv.setImageDrawable(getResources().getDrawable(R.drawable.icon48x48_1));
+ iv.setPadding(4, 4, 4, 4);
+ layout.addView(iv);
+ }
+ };
+
+ private OnClickListener mRemoveContentListener = new OnClickListener() {
+ public void onClick(View v) {
+ LinearLayout layout = (LinearLayout)findViewById(R.id.inner_content);
+ int num = layout.getChildCount();
+ if (num > 0) {
+ layout.removeViewAt(num-1);
+ }
+ }
+ };
}