zoukankan      html  css  js  c++  java
  • android DialogFragment 实现Dialog展示扫二维码图片展示

         近期开发项目,做个按钮点击弹出展示微信二维码关注微信公众号的展示框,于是想到DialogFragment,期间对Dialog的title的底框字体颜色做出相关设置,记录如下:

        下面是 DialogFragment.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center_horizontal|center_vertical">
    
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/wechat"
            android:layout_marginBottom="5dp"
            android:layout_marginTop="20dp"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="关注后提醒用户登录账户"
            android:textColor="#e70012"
            android:textSize="18dp"
            android:layout_marginBottom="20dp"/>
    </LinearLayout>

       DialogFragment.java:

    public class FragmentDialogWeChatImage extends DialogFragment{
    
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
            View mView=inflater.inflate(R.layout.fragment_dialog_wechat_image,container,false);
            getDialog().setTitle("扫码关注微信公众号");//设置Dialog字体颜色
            TextView title=(TextView) getDialog().findViewById(android.R.id.title);
            title.setTextColor(getResources().getColor(R.color.red));//设置字体颜色
            title.setGravity(Gravity.CENTER_HORIZONTAL|Gravity.CENTER_VERTICAL);//设置字体水平居中
    
            int titleDividerId = getResources().getIdentifier("titleDivider", "id", "android");
            View titleDivider = getDialog().findViewById(titleDividerId);
            if (titleDivider != null) {
                titleDivider.setBackgroundColor(getResources().getColor(android.R.color.holo_red_light));//设置标题底线color
            }
            return mView;
        }
    
    }

    点击按钮实现弹出DialogFragment:

       /**
         * 点击关联微信
         */
        @OnClick(R.id.txt_relation_wechat)
        public void onClickWechat(View view){
            FragmentDialogWeChatImage fdw=new FragmentDialogWeChatImage();
            FragmentTransaction ft=getFragmentManager().beginTransaction();
            ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
            fdw.show(ft,"fdw");
        }
  • 相关阅读:
    在Ubuntu18.04.2LTS上安装搜狗输入法
    生活点滴:java基础知识细化
    乘风破浪:LeetCode真题_041_First Missing Positive
    乘风破浪:LeetCode真题_040_Combination Sum II
    乘风破浪:LeetCode真题_039_Combination Sum
    乘风破浪:LeetCode真题_038_Count and Say
    乘风破浪:LeetCode真题_037_Sudoku Solver
    乘风破浪:LeetCode真题_036_Valid Sudoku
    乘风破浪:LeetCode真题_035_Search Insert Position
    乘风破浪:LeetCode真题_034_Find First and Last Position of Element in Sorted Array
  • 原文地址:https://www.cnblogs.com/zty-Love/p/8664683.html
Copyright © 2011-2022 走看看