zoukankan      html  css  js  c++  java
  • Android 自定义对话框

    public class CustomDilaog {
    
        private Context context;
        private Dialog dialog;
    
        public CustomDilaog(Context context) {
    
            this.context = context;
            dialog = new Dialog(context);
        }
    
        public 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="match_parent"
        android:orientation="horizontal"
        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:text="自定义对话框内容"
            android:textColor="#000000" />
    
    </LinearLayout>
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            button = (Button) findViewById(R.id.button);
            button.setOnClickListener(new OnClickListener() {
    
                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    CustomDilaog dilaog = new CustomDilaog(MainActivity.this);
                    dilaog.show();
                }
            });
        }

    image

  • 相关阅读:
    [BZOJ2738]矩阵乘法
    [BZOJ2084][Poi2010]Antisymmetry
    [BZOJ2095][Poi2010]Bridges
    [BZOJ1294][SCOI2009]围豆豆Bean
    [AtCoderContest075F]Mirrored
    [AtCoderContest015D]A or...or B Problem
    [UOJ#276]【清华集训2016】汽水
    忠诚的皇家守卫团——中间件
    Django(五):视图和路由系统
    Django(四):ORM
  • 原文地址:https://www.cnblogs.com/zhangxuechao/p/11798173.html
Copyright © 2011-2022 走看看