android alertDialog 使用
来源:互联网 发布:护士幻灯片制作软件 编辑:程序博客网 时间:2024/06/15 14:56
描述:点击button,弹出对话框;另外ImageView显示图片
包含四个文件:main.xml,MainActivity,androidManifest.xml
1.main.xml文件内容
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:layout_width="200dp"
android:layout_height="100dp"
android:id="@+id/button1" >
</Button>
<ImageView
android:layout_width="200dp"
android:layout_height="100dp"
android:id="@+id/imageView1">
</ImageView>
</LinearLayout>
2.MainActivity
public class MainActivity extends Activity {
public Button mButton;
public ImageView mImageView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mButton = (Button) findViewById(R.id.button1);
mImageView = (ImageView) findViewById(R.id.imageView1);
mImageView.setImageResource(R.drawable.ic_launcher);
mButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Dialog alertDialog = new AlertDialog.Builder(MainActivity.this).
setTitle(R.string.dialog_title).
setMessage(R.string.dialog_content).
setIcon(R.drawable.ic_launcher).
setPositiveButton(R.string.button_content, null).
setNegativeButton("Cancel", null).
create();
alertDialog.show();
}
});
}
}
3.string.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">TestAlertDialog</string>
<string name="title_activity_main">MainActivity</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
<string name="dialog_title">演示框</string>
<string name="dialog_content">Hello, this world</string>
<string name="button_content">确定</string>
</resources>
4.androidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xinhua.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
- android alertDialog的使用
- android基础AlertDialog使用
- Android AlertDialog使用
- android alertDialog 使用
- Android系统AlertDialog使用
- Android中AlertDialog使用
- android之使用AlertDialog
- Android Alertdialog使用案例
- Android AlertDialog使用
- Android之AlertDialog的使用
- android开发-使用Dialog AlertDialog
- 25、Android之AlertDialog使用
- android开发-使用Dialog AlertDialog
- Android中自定义AlertDialog使用
- android开发-使用Dialog AlertDialog
- Android中AlertDialog的使用
- Android中AlertDialog的使用
- Android中自定义AlertDialog使用
- qt quick编程
- Redis使用心得一 の 环境配置
- 【面试】京东成都研发部面试
- Java实现定时任务的三种方法
- [iOS] 使用 CocoaPods 管理第三方套件
- android alertDialog 使用
- 两个有序数组合并成一个有序数组
- 第4章 第2题
- Android自定义进度条
- maven spring mvc project的配置
- 四种生成和解析XML文档的方法详解(介绍+优缺点比较+示例)
- Nginx 0.8.x + PHP 5.2.13(FastCGI)搭建胜过Apache十倍的Web服务器(第6版)[原创]
- POJ 1423 BIG NUMBER
- Spring 3 AOP 概念介绍