package com.test;
import Android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.text.Layout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
public class test extends Activity implements OnClickListener {
private ImageButton button=null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button=(ImageButton)findViewById(R.id.button);
//监听
button.setOnClickListener(this);
}
@Override
public void onClick(View v) {
Windows();
}
private void Windows() {
//接受一些参数如:图片,标题,正文
AlertDialog.Builder builder;
AlertDialog alertDialog;
//加载和访问资源
Context mContext =test.this;
//通过LayoutInlater得到上面xml布局的View view
LayoutInflater inflater =
(LayoutInflater)mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout =inflater.inflate(R.layout.custom_dialog,null);
//绑定test和image
TextView text=(TextView)layout.findViewById(R.id.text);
text.setText("hello");
Button b =(Button)layout.findViewById(R.id.b);
b.setText("butto");
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
System.out.println("123");
}
});
ImageView image=(ImageView)layout.findViewById(R.id.image);
//取出系统自带的图片
image.setImageResource(R.drawable.icon);
//加载
builder = new AlertDialog.Builder(mContext);
builder.setView(layout);
//创建目标,这里创建相应的AlertDialog
// alertDialog = builder.create();
//弹出窗口
builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
}
}).setNegativeButton("取消",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
dialog.cancel();
}
}).create();
builder.show();
}
}
<?xml version="1.0"
encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
>
<ImageView android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginRight="10dp"
/>
<TextView android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:textColor="#FFF"
/>
<Button android:id="@+id/b"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
/>
</LinearLayout>
<?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="@string/hello" /> <ImageButton android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="#000000" android:src="@drawable/icon" /> </LinearLayout>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有