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");
        }
  • 相关阅读:
    自定义函数
    取小数的有效值函数
    数据恢复bak
    脚本启动windows服务
    创建表
    PostgreSQL和SQL SERVER的数据库差异
    vs2019莫名自动退出调试状态
    postgresql 设置调试
    Google Web字体,让你的网页更迷人
    翻译:观察者模式—使用JavaScript实现
  • 原文地址:https://www.cnblogs.com/zty-Love/p/8664683.html
Copyright © 2011-2022 走看看