android alertdialog 弹出框
16lz
2021-12-04
LayoutInflater的应用
MyTestActivity.java
package com.android.demo;import android.app.Activity;import android.app.AlertDialog;import android.content.Context;import android.content.DialogInterface;import android.os.Bundle;import android.view.LayoutInflater;import android.view.View;import android.widget.TextView;public class MyTestActivity extends Activity { @Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.main); Context mContext = MyTestActivity.this; //下面俩种方法都可以 //LayoutInflater inflater = getLayoutInflater(); LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.custom_dialog,null); TextView text = (TextView) layout.findViewById(R.id.text); text.setText(" 感谢您选择使用金软office办公软件,请注册并激活软件,即可获得软件正式版的使用权。"); new AlertDialog.Builder(MyTestActivity.this).setIcon(android.R.drawable.ic_menu_info_details).setTitle("金软Office[试用版]").setView(layout).setPositiveButton("确定", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {// TODO Auto-generated method stub}}).show();}}XML文件:custom_dialog.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" ><TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="试用期剩余14天" android:gravity="center" /><TextView android:id="@+id/text" android:layout_width="fill_parent" android:layout_height="wrap_content" /><EditText android:id="@+id/edit" android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="请输入email......" /></LinearLayout>
EditText中的提示:
android:hint="请输入email......"效果图
更多相关文章
- android 弹出软盘
- android软件开发:横竖屏
- android页面管理器。可以实现完整退出android软件
- android中软件参数保存
- android软件工程师/android中间件开发
- Android使用SAX解析XML(1)
- 新的Android恶意软件出现!可能窃取你的银行密码
- Android软件开发需要学什么
- MIUI 惊艳锁屏样式5款[Android] | 小众软件 > Android