美文网首页
TDialog 实例 从下方弹起 列表框,展示 相机和相册

TDialog 实例 从下方弹起 列表框,展示 相机和相册

作者: 勤劳的蚂蚁 | 来源:发表于2020-03-11 11:41 被阅读0次
image.png


import java.util.HashMap;
import java.util.Map;

/**
 * Created by 41113 on 2018/9/30.
 */

public class PhotoDialog extends TDialog {

    private final int CAMERA = 1000;//调用相机
    private final int IMAGES = 2000;//打开相册

    public PhotoDialog() {
        super ();
    }

    public void showDialog(FragmentManager fragmentManager, final Activity context, final ChooseListener chooseListener) {
        this.chooseListener = chooseListener;
        new Builder (fragmentManager)
                .setLayoutRes (R.layout.dialog_photo_change)
                .setScreenWidthAspect (context, 1.0f)
                .setGravity (Gravity.BOTTOM)
                .setDialogAnimationRes (R.style.QRCodeAnim)
                .addOnClickListener (R.id.tv_camera, R.id.tv_change_photo)
                .setOnViewClickListener (new OnViewClickListener () {
                    @Override
                    public void onViewClick(BindViewHolder viewHolder, View view, final TDialog tDialog) {
                        switch (view.getId ()) {
                            case R.id.tv_camera:
    //添加权限判断

                                if (chooseListener != null) {
                                    chooseListener.chooseCamera ();
                                }
                                tDialog.dismiss ();

                                break;
                            case R.id.tv_change_photo:
    //添加权限判断
                                if (chooseListener != null) {
                                    chooseListener.chooseImages ();
                                }
                                tDialog.dismiss ();


                                break;
                            default:
                                break;
                        }
                    }
                })
                .create ()
                .show ();
    }

    private ChooseListener chooseListener;

    public interface ChooseListener {

        void chooseCamera();

        void chooseImages();
    }
}


dialog_photo_change 文件 :
<?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:background="#7f7f7f"
    android:clipToPadding="true"
    android:fitsSystemWindows="true"
    android:gravity="bottom"
    android:orientation="vertical">

    <TextView
        android:id="@+id/tv_camera"
        android:layout_width="match_parent"
        android:layout_height="@dimen/video_column55"
        android:background="@color/colorWhite"
        android:gravity="center"
        android:text="拍照"
        android:textColor="@drawable/selector_login_popwin_itemcolor"
        android:textSize="@dimen/text14" />

    <View
        android:layout_width="match_parent"
        android:layout_height="@dimen/line_width"
        android:background="@color/line_bg" />

    <TextView
        android:id="@+id/tv_change_photo"
        android:layout_width="match_parent"
        android:layout_height="@dimen/video_column55"
        android:background="@color/colorWhite"
        android:gravity="center"
        android:text="从手机相册中选泽"
        android:textColor="@drawable/selector_login_popwin_itemcolor"
        android:textSize="@dimen/text14" />

</LinearLayout>


文件selector_login_popwin_itemcolor:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:color="#ff5722" android:state_selected="true" />
    <item android:color="#ff5722" android:state_focused="true" />
    <item android:color="#ff5722" android:state_pressed="true" />
    <item android:color="#333333" />
</selector>

相关文章

网友评论

      本文标题:TDialog 实例 从下方弹起 列表框,展示 相机和相册

      本文链接:https://www.haomeiwen.com/subject/qwdqjhtx.html