Android 自定义对话框
发布时间:2020-12-15 07:17:08 所属栏目:Java 来源:网络整理
导读:public class CustomDilaog { private Context context; Dialog dialog; public CustomDilaog(Context context) { this .context = context; dialog = new Dialog(context); } void show() { View view = LayoutInflater.from(context).inflate(R.layout.cus
public class CustomDilaog { private Context context; Dialog dialog; public CustomDilaog(Context context) { this.context = context; dialog = new Dialog(context); } void show() { View view = LayoutInflater.from(context).inflate(R.layout.custom,null); dialog.setContentView(view); dialog.setTitle("自定义对话框"); ImageView imageView = (ImageView) view.findViewById(R.id.image); imageView.setImageResource(R.drawable.a1); dialog.show(); } } <?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
android:orientation="horizontal"
android:padding="10dp" >
ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginRight/>
TextView
="@+id/text"
android:text="自定义对话框内容"
android:textColor="#000000" />
</LinearLayout>
protected onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.button);
button.setOnClickListener( OnClickListener() {
@Override
onClick(View v) {
// TODO Auto-generated method stub
CustomDilaog dilaog = new CustomDilaog(MainActivity.this);
dilaog.show();
}
});
}
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |