• 自定义Dialog


    如图是效果图,第一个按钮当按下时弹出一个自定义的Dialog,第二个和第三个分别是ProgressBar,只是简单的改变了样式

    第1个ProgressBar是逆时针方向,第2 个时顺时针方向

                                     

    如下是主代码

    package com.demo.sb.main;
    
    import com.demo.suibian.R;
    import android.app.Activity;
    import android.app.AlertDialog;
    import android.os.Bundle;
    import android.view.Display;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.view.WindowManager;
    import android.widget.Button;
    import android.widget.Toast;
    
    public class Activity_Dialog extends Activity implements OnClickListener {
        private Button btn_dialog;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_dialog);
            btn_dialog = (Button) findViewById(R.id.btn_dialog);
            btn_dialog.setOnClickListener(this);
        }
    
        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            switch (arg0.getId()) {
            case R.id.btn_dialog:
                initDialog();
                break;
    
            default:
                break;
            }
        }
    
        private void initDialog() {
            // TODO Auto-generated method stub
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setCancelable(false);
            final AlertDialog dialog = builder.create();
            View view = View.inflate(this, R.layout.item_dialog, null);
            dialog.setView(view, 0, 0, 0, 0);
            Button btnCancel = (Button) view.findViewById(R.id.btn_cancel);
            Button btnOk = (Button) view.findViewById(R.id.btn_ok);
            btnOk.setOnClickListener(new View.OnClickListener() {
    
                @Override
                public void onClick(View arg0) {
                    // TODO Auto-generated method stub
                    Toast.makeText(Activity_Dialog.this, "queding",
                            Toast.LENGTH_SHORT).show();
                    dialog.dismiss();
                }
            });
            btnCancel.setOnClickListener(new View.OnClickListener() {
    
                @Override
                public void onClick(View arg0) {
                    // TODO Auto-generated method stub
                    dialog.dismiss();
                }
            });
            dialog.show();
            /**
             * 改变Dialog在屏幕显示的位置
             */
            WindowManager manager = getWindowManager();
            Display display = manager.getDefaultDisplay();
            android.view.WindowManager.LayoutParams params = dialog.getWindow()
                    .getAttributes();
            params.height = (int) (display.getHeight() * 0.4);
            params.width = (int) (display.getWidth() * 0.75);
            params.x = 10;
            params.y = 150;
            dialog.getWindow().setAttributes(params);
        }
    
    }

    布局文件

    <?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="vertical" >
    
        <Button
            android:id="@+id/btn_dialog"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    
        <ProgressBar
            android:id="@+id/pb_dialog_one"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:layout_gravity="center"
            android:indeterminateDrawable="@drawable/indeterminate_drawable"
            android:indeterminateDuration="1000" />
    
        <View
            android:layout_width="match_parent"
            android:layout_height="2dp"
            android:layout_marginTop="5dp"
            android:layout_marginBottom="5dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:background="#000" />
    
        <ProgressBar
            android:id="@+id/pb_dialog_two"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:background="#2000"
            android:indeterminateDrawable="@drawable/custom_progress" >
        </ProgressBar>
    
    </LinearLayout>
    <?xml version="1.0" encoding="utf-8"?>
    <rotate xmlns:android="http://schemas.android.com/apk/res/android" 
        android:fromDegrees="360"
        android:pivotX="50%"
        android:pivotY="50%"
        android:drawable="@drawable/pic"
        android:toDegrees="0">
        
    
    </rotate>
    <?xml version="1.0" encoding="utf-8"?>
    <rotate xmlns:android="http://schemas.android.com/apk/res/android"
        android:fromDegrees="0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toDegrees="360" >
    
        <shape
            android:innerRadius="12dp"
            android:shape="ring"
            android:thickness="3dp"
            android:useLevel="false" >
            <gradient
                android:centerColor="#3f00"
                android:endColor="#f00"
                android:startColor="#fff" />
        </shape>
    
    </rotate>
  • 相关阅读:
    nginx nfs服务
    Linux磁盘分区-rpm-yum
    tar命令-vi编辑器-磁盘分区及格式化-软链接及硬链接文件
    Linux命令-权限
    Linux命令基础
    网络基础
    操作系统
    计算机硬件介绍
    Django之CBV和FBV
    ORM之基本操作增删改查
  • 原文地址:https://www.cnblogs.com/wangfengdange/p/5163066.html
Copyright © 2020-2023  润新知