模仿网易新闻,点击举报按钮,弹出举报对话框

来源:互联网 发布:人工智能的原理是什么? 编辑:程序博客网 时间:2024/04/30 11:49

想看一下网易的效果吧
这里写图片描述

看起来还不错,那我们现在就模仿一下网易,也实现相同的效果吧

1.创建MyCustomDialog集成Dialog

private Context context;    private  TextView tv1;    private  TextView tv2;    private  TextView tv3;    private  TextView tv4;    private  TextView tv5;//    public MyCustomDialog(Context context) {        this(context, R.style.dialog);        this.context = context;    }//有两个参数的构造函数,themeResId可以定制Dialog的样式    public MyCustomDialog(Context context, int themeResId) {        super(context, themeResId);        View contentView = UIUtils.inflate(R.layout.dialog_accuse_complaint);        tv1 = (TextView) contentView.findViewById(R.id.tv1);        tv2 = (TextView) contentView.findViewById(R.id.tv2);        tv3 = (TextView) contentView.findViewById(R.id.tv3);        tv4 = (TextView) contentView.findViewById(R.id.tv4);        tv5 = (TextView) contentView.findViewById(R.id.tv5);        setListener();        requestWindowFeature(Window.FEATURE_NO_TITLE);        super.setContentView(contentView);    }    /**     * 设置监听     */    private void setListener() {        tv1.setOnClickListener(this);        tv2.setOnClickListener(this);        tv3.setOnClickListener(this);        tv4.setOnClickListener(this);        tv5.setOnClickListener(this);    }    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        // 设置为底部显示        getWindow().setGravity(Gravity.BOTTOM);        WindowManager m = getWindow().getWindowManager();        Display d = m.getDefaultDisplay();        // 设置宽度填充屏幕        WindowManager.LayoutParams p = getWindow().getAttributes();        p.width = d.getWidth();        getWindow().setAttributes(p);    }    @Override    public void onClick(View v) {        switch (v.getId()){            case R.id.tv1:                break;            case R.id.tv2:                break;            case R.id.tv3:                break;            case R.id.tv4:                break;            case R.id.tv5:                break;        }    }

2.dialog_custom.xml如下

<?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">    <TextView        android:id="@+id/tv1"        style="@style/accuse_style"        android:text="营销诈骗" />    <View        android:layout_width="match_parent"        android:layout_height="1px"        android:background="@color/color_division_line" />    <TextView        android:id="@+id/tv2"        style="@style/accuse_style"        android:text="淫秽色情" />    <View        android:layout_width="match_parent"        android:layout_height="1px"        android:background="@color/color_division_line" />    <TextView        android:id="@+id/tv3"        style="@style/accuse_style"        android:text="地域攻击" />    <View        android:layout_width="match_parent"        android:layout_height="1px"        android:background="@color/color_division_line" />    <TextView        android:id="@+id/tv4"        style="@style/accuse_style"        android:text="其他理由" />    <View        android:layout_width="match_parent"        android:layout_height="1px"        android:background="@color/color_division_line" />    <TextView        android:id="@+id/tv5"        style="@style/accuse_style"        android:layout_marginBottom="20dp"        android:text="取消" /></LinearLayout>

3.accuse_style样式如下

     <style name="accuse_tucao_style">        <item name="android:layout_width">match_parent</item>        <item name="android:layout_height">wrap_content</item>        <item name="android:padding">10dp</item>        <item name="android:textSize">16sp</item>        <item name="android:layout_marginRight">20dp</item>        <item name="android:layout_marginLeft">20dp</item>        <item name="android:layout_marginTop">10dp</item>        <item name="android:gravity">center</item>        <item name="android:background">@drawable/dialog_accuse_shape</item>        <item name="android:clickable">true</item>        <item name="android:textColor">#858585</item>    </style>

4.dialog_accuse_shape

    <?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android"    android:shape="rectangle" >    <solid android:color="@color/color_white" />//边框    <!--<stroke    //边框颜色        android:color="#F3F4F5"        //边框宽度        android:width="1px"        >    </stroke>--></shape>

5.R.style.dialog代码如下

    <!--自定义对话框样式-->    <style name="dialog" parent="Base.Theme.AppCompat.Light.Dialog.FixedSize">        <item name="android:windowBackground">@color/color_white</item>        <item name="android:windowAnimationStyle">@style/dialog_animation</item>    </style>    <style name="dialog_animation" parent="android:Animation">        //进入动画        <item name="@android:windowEnterAnimation">@anim/slide_enter_bottom</item>        //退出动画        <item name="@android:windowExitAnimation">@anim/slide_exit_bottom</item>    </style>

6.slide_enter_bottom.xml,slide_exit_bottom.xml 如下

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android">    <translate        android:duration="300"        android:fromYDelta="100%"        android:toYDelta="0" />    <alpha        android:duration="300"        android:fromAlpha="0.0"        android:toAlpha="1.0" /></set>
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" >    <translate        android:duration="300"        android:fromYDelta="0"        android:toYDelta="100%" />    <alpha        android:duration="300"        android:fromAlpha="1.0"        android:toAlpha="0.0" /></set>

7.只需要在Activity中调用如下代码即可

                     MyCustomDialog   myCustomDialog= new AccuseComplaintDialog(MainActivity.this);                    myCustomDialog.setAccuseId(complaint.getAuthId());                    //Sets whether this dialog is cancelable with the BACK key.                    myCustomDialog.setCancelable(true);                    myCustomDialog.setCanceledOnTouchOutside(true);                    myCustomDialog.show();

效果如下这里写图片描述

1 0
原创粉丝点击