<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <EditText android:id="@+id/et_tel" android:layout_width="fill_parent" android:layout_height="47dp" android:layout_marginLeft="17dp" android:layout_marginRight="17dp" android:layout_marginTop="50dp" android:background="@drawable/bg_input" android:hint="请输入手机号码" android:paddingLeft="17dp" android:paddingRight="17dp" android:textColor="#666666" android:textColorHint="#bbbbbb" android:textSize="16dp" android:typeface="sans" /> </RelativeLayout>
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/root_guide_contact_dialog" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:id="@+id/img_registe_input" android:layout_width="fill_parent" android:layout_height="47dp" android:layout_marginTop="50dp" android:background="@drawable/bg_registe_input"/> <ImageView android:id="@+id/img_registe_tip" android:layout_width="fill_parent" android:layout_height="155dp" android:layout_marginTop="120dp" android:background="@drawable/bg_registe_tip"/> </RelativeLayout>
package com.example.guideregiste; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.Window; import android.widget.EditText; public class MainActivity extends Activity { public EditText et_tel; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //去头部 requestWindowFeature(Window.FEATURE_NO_TITLE); //加载布局文件 setContentView(R.layout.regist); //获取控件 et_tel =(EditText)findViewById(R.id.et_tel); //显示alertDialog RegisteFunctionGuideDlg.getInstance(MainActivity.this,et_tel).show(); } }
package com.example.guideregiste; import android.app.Dialog; import android.content.Context; import android.graphics.Color; import android.os.Bundle; import android.view.Gravity; import android.view.View; import android.view.Window; import android.widget.ImageView; public class RegisteFunctionGuideDlg extends Dialog { private Context context ; private static View mClickView; private static RegisteFunctionGuideDlg functionGuideDlg = null; /**构造器*/ private RegisteFunctionGuideDlg(Context context) { //全屏 super(context, android.R.style.Theme_Translucent_NoTitleBar); this.context = context; } public static RegisteFunctionGuideDlg getInstance(Context ctx,View view) { mClickView = view; if (functionGuideDlg == null) { functionGuideDlg = new RegisteFunctionGuideDlg(ctx); } return functionGuideDlg; } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.guide_registe); //获取dialog的布局id View rootView = findViewById(R.id.root_guide_contact_dialog); //设置颜色背景 rootView.setBackgroundColor(Color.argb(150, 0, 0, 0)) ; ImageView img_input = (ImageView)findViewById(R.id.img_registe_input) ; img_input.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dismiss(); } }) ; getWindow().setGravity(Gravity.TOP); } }
原文地址:http://blog.csdn.net/u013210620/article/details/46375143