* commit '531ebcdc40909b21c64d5b7f740f2201a9a8cbd5': AlertDialog Demo
This commit is contained in:
@@ -298,6 +298,15 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
|
<activity android:name=".app.AlertDialogUsage"
|
||||||
|
android:label="@string/alert_dialog_usage"
|
||||||
|
android:theme="@style/Theme.AppCompat.Light">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
<category android:name="com.example.android.supportv7.SAMPLE_CODE" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
|
||||||
<provider android:name=".app.RecentSuggestionsProvider"
|
<provider android:name=".app.RecentSuggestionsProvider"
|
||||||
android:authorities="com.example.android.supportv7.RecentSuggestionsProvider" />
|
android:authorities="com.example.android.supportv7.RecentSuggestionsProvider" />
|
||||||
|
|
||||||
|
|||||||
38
samples/Support7Demos/res/layout/alert_dialog_usage.xml
Normal file
38
samples/Support7Demos/res/layout/alert_dialog_usage.xml
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
Copyright (C) 2015 The Android Open Source Project
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:padding="16dp">
|
||||||
|
|
||||||
|
<Spinner
|
||||||
|
android:id="@+id/spinner_dialogs"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:entries="@array/alert_dialog_types"
|
||||||
|
android:layout_marginBottom="16dp"/>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/btn_show_dialog"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Show selected dialog"
|
||||||
|
android:gravity="center"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
@@ -35,4 +35,11 @@
|
|||||||
<item>Button bar</item>
|
<item>Button bar</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="alert_dialog_types">
|
||||||
|
<item>Simple</item>
|
||||||
|
<item>Simple with buttons</item>
|
||||||
|
<item>List (single choice)</item>
|
||||||
|
<item>List (multi choice)</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -135,6 +135,7 @@
|
|||||||
<string name="dialog_usage">AppCompat/Dialog/Dialog Usage</string>
|
<string name="dialog_usage">AppCompat/Dialog/Dialog Usage</string>
|
||||||
<string name="dialog_title">My great dialog</string>
|
<string name="dialog_title">My great dialog</string>
|
||||||
<string name="dialog_content">My great dialog is great</string>
|
<string name="dialog_content">My great dialog is great</string>
|
||||||
|
<string name="alert_dialog_usage">AppCompat/Dialog/AlertDialog Usage</string>
|
||||||
|
|
||||||
<string name="sample_media_route_provider_remote">Remote Playback (Simulated)</string>
|
<string name="sample_media_route_provider_remote">Remote Playback (Simulated)</string>
|
||||||
<string name="sample_media_route_activity_local">Local Playback</string>
|
<string name="sample_media_route_activity_local">Local Playback</string>
|
||||||
|
|||||||
@@ -0,0 +1,101 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2015 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.example.android.supportv7.app;
|
||||||
|
|
||||||
|
import com.example.android.supportv7.Cheeses;
|
||||||
|
import com.example.android.supportv7.R;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.v7.app.AlertDialog;
|
||||||
|
import android.support.v7.app.AppCompatActivity;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Spinner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This demonstrates idiomatic usage of AppCompat's AlertDialog.
|
||||||
|
*/
|
||||||
|
public class AlertDialogUsage extends AppCompatActivity {
|
||||||
|
|
||||||
|
private Spinner mSpinner;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.alert_dialog_usage);
|
||||||
|
|
||||||
|
mSpinner = (Spinner) findViewById(R.id.spinner_dialogs);
|
||||||
|
|
||||||
|
// Add an OnClickListener to show our selected dialog
|
||||||
|
findViewById(R.id.btn_show_dialog).setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
showSelectedDialog();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showSelectedDialog() {
|
||||||
|
switch (mSpinner.getSelectedItemPosition()) {
|
||||||
|
case 0:
|
||||||
|
showSimpleDialog();
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
showSimpleButtonsDialog();
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
showSingleChoiceDialog();
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
showMultiChoiceDialog();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showSimpleDialog() {
|
||||||
|
AlertDialog.Builder b = new AlertDialog.Builder(this);
|
||||||
|
b.setTitle(R.string.dialog_title);
|
||||||
|
b.setMessage(R.string.dialog_content);
|
||||||
|
b.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showSimpleButtonsDialog() {
|
||||||
|
AlertDialog.Builder b = new AlertDialog.Builder(this);
|
||||||
|
b.setTitle(R.string.dialog_title);
|
||||||
|
b.setMessage(R.string.dialog_content);
|
||||||
|
b.setNegativeButton("-ve", null);
|
||||||
|
b.setPositiveButton("+ve", null);
|
||||||
|
b.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showSingleChoiceDialog() {
|
||||||
|
AlertDialog.Builder b = new AlertDialog.Builder(this);
|
||||||
|
b.setTitle(R.string.dialog_title);
|
||||||
|
b.setSingleChoiceItems(Cheeses.sCheeseStrings, 0, null);
|
||||||
|
b.setPositiveButton("OK", null);
|
||||||
|
b.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showMultiChoiceDialog() {
|
||||||
|
AlertDialog.Builder b = new AlertDialog.Builder(this);
|
||||||
|
b.setTitle(R.string.dialog_title);
|
||||||
|
b.setMultiChoiceItems(Cheeses.sCheeseStrings, null, null);
|
||||||
|
b.setPositiveButton("OK", null);
|
||||||
|
b.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user