splashActivity使用主题代替layout

 <activity
            android:name=".SplashActivity"
            android:screenOrientation="portrait"
            android:theme="@style/SplashTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
<!--启动页的绘制-->
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowTranslucentNavigation">true</item>
    <item name="windowActionBar">false</item>
    <item name="android:windowBackground">@drawable/splash_background</item>
</style>
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="@android:color/background_light" />
        </shape>
    </item>
    <item android:top="100dp" android:gravity="top">
        <bitmap
            android:gravity="top"
            android:src="@mipmap/splash_study" />
    </item>
    <item android:top="456dp" android:gravity="center" android:bottom="115dp">
        <bitmap
            android:gravity="center"
            android:src="@mipmap/splash_logo" />
    </item>
    <item android:gravity="bottom" android:bottom="10dp">
        <bitmap
            android:gravity="bottom"
            android:src="@mipmap/splash_tech_support" />
    </item>
</layer-list>
  /**
     * 展示用户隐私和用户协议的弹窗
     */
    public void showAgreementDialog() {
        final MaterialDialog.Builder builder = new MaterialDialog.Builder(mContext)
                .customView(R.layout.agreement_notice_dialog_layout, false);
        final MaterialDialog dialog = builder.build();
        View customView = dialog.getCustomView();

        if (customView != null && mContext != null) {
            final String appName = mContext.getResources().getString(R.string.application_name);
            String content = String.format(mContext.getResources().getString(R.string.agreement_dialog_start), appName);
            TextView contentTv = customView.findViewById(R.id.agreement_content);
            // 设置样式
            SpannableStringBuilder stringBuilder = new SpannableStringBuilder(content);
            ForegroundColorSpan agreementSpan = new ForegroundColorSpan(mContext.getResources().getColor(R.color.main_theme_color));
            // 设置点击时间
            NoLineClickSpan agreementClick = new NoLineClickSpan() {
                @Override
                public void onClick(@NonNull View view) {
                    toWebView(1, appName);
                }
            };
            ForegroundColorSpan privacySpan = new ForegroundColorSpan(mContext.getResources().getColor(R.color.main_theme_color));

            NoLineClickSpan privacy = new NoLineClickSpan() {
                @Override
                public void onClick(@NonNull View view) {
                    toWebView(2, appName);
                }
            };
            stringBuilder.setSpan(agreementSpan, content.length() - 16, content.length() - 10, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            stringBuilder.setSpan(privacySpan, content.length() - 9, content.length() - 3, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

            stringBuilder.setSpan(agreementClick, content.length() - 16, content.length() - 10, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            stringBuilder.setSpan(privacy, content.length() - 9, content.length() - 3, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            contentTv.setText(stringBuilder);
            //设置了点击事件后请加上这句,不然点击事件不起作用
            contentTv.setMovementMethod(LinkMovementMethod.getInstance());

            TextView disagree = customView.findViewById(R.id.agreement_disagree);
            TextView agree = customView.findViewById(R.id.agreement_agree);
            disagree.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    AppManager.getAppManager().AppExit();
                    dialog.dismiss();
                }
            });

            agree.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    // 保存同意的状态
                    dialog.dismiss();
                    SPUtils.getInstance().put(SPKeyGlobal.AGREE_Agreement, true);
                    clickListener.agree();

                }
            });
            dialog.setCanceledOnTouchOutside(false);
            dialog.setCancelable(false);
            dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dialogInterface) {
                }
            });
            Objects.requireNonNull(dialog.getWindow()).setBackgroundDrawableResource(R.color.transparent);
            dialog.show();
        }
    }

    private void toWebView(int type, String appName) {
        String baseUrl;
        if (type == 1) {
            baseUrl = BuildConfigHelper.getAgreementUrl();
        } else {
            baseUrl = BuildConfigHelper.getPrivacyPolicyUrl();
        }
        int trainingId = SPUtils.getInstance().getInt(SPKeyGlobal.TRAINING_INSTITUTION_ID, 0);
        String url = "";
        Bundle bundle = new Bundle();
        Intent intent = new Intent(mContext, Activity.class);
        bundle.putString(BundleKey.BUNDLE_KEY_H5_URL, url);
        intent.putExtras(bundle);
        mContext.startActivity(intent);
    }

    //自定义类继承自ClickableSpan。用该类来代替使用
    public abstract class NoLineClickSpan extends ClickableSpan {
        public NoLineClickSpan() {
            super();
        }

        @Override
        public void updateDrawState(TextPaint ds) {
            //set textColor/
            ds.setColor(ds.linkColor);
            //Remove the underline
            ds.setUnderlineText(false);
        }

        @Override
        public abstract void onClick(@NonNull View view);
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值