<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          Android實現(xiàn)不同字體顏色設(shè)置不同的點擊事件

          共 3421字,需瀏覽 7分鐘

           ·

          2022-01-13 00:55

          由于目前APP的上架需求,有的商城已經(jīng)開始了免責(zé)聲明,雖然不知道這樣做是好是壞,但是需求在那我們就必須去實現(xiàn)了╮(╯▽╰)╭先看下效果圖:


          在需求中我們需要將下面的文字放到一起,并更改不同的顏色進(jìn)行區(qū)分,還需要將用《用戶協(xié)議》《隱私政策》添加不同的點擊事情,去跳轉(zhuǎn)進(jìn)行展示不同的說明

          首先這是一個彈框,我們需要先去定義它的布局文件

          <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="250dp"    android:layout_height="wrap_content"    android:background="@drawable/bg_white_5dp"    android:orientation="vertical">
          <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:paddingTop="30dp" android:text="用戶協(xié)議和隱私政策" android:textColor="@color/color_111111" android:textSize="15sp" />
          <TextView android:id="@+id/tv_content" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_vertical" android:lineSpacingMultiplier="1.3" android:paddingStart="15dp" android:paddingTop="14dp" android:paddingEnd="15dp" android:paddingBottom="20dp" android:text="" android:textColor="@color/color_333333" android:textSize="13sp" />
          <View android:layout_width="match_parent" android:layout_height="1dp" android:background="#EEEEEE" />
          <LinearLayout android:layout_width="match_parent" android:layout_height="50dp" android:orientation="horizontal">
          <TextView android:id="@+id/tv_cancel" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:gravity="center" android:text="暫不使用" android:textColor="@color/color_333333" android:textSize="16sp" />
          <View android:layout_width="1dp" android:layout_height="match_parent" android:background="#EEEEEE" />
          <TextView android:id="@+id/tv_sure" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:gravity="center" android:text="同意" android:textColor="@color/colorMain" android:textSize="16sp" /> LinearLayout>LinearLayout>

          然后我們需要去定義一個條件去判斷是否是第一次打開軟件,如果是的話彈出我們這個攤款,如果不是的話則不彈出

          //第一次打開APP彈出彈框if (StringUtils.isEmpty(MyApplication.getIsNew())) {    showDialog();}


          接下來就是針對dialog的操作,直接上干貨

           private void showDialog() {        final Dialog mDialog;        mDialog = new Dialog(this, R.style.Teldialog);        mDialog.setContentView(R.layout.dialog_show);        mDialog.setCanceledOnTouchOutside(false);        mDialog.setCancelable(false);        mDialog.show();        TextView content = mDialog.findViewById(R.id.tv_content);
          String str = "請您務(wù)必審慎閱讀、充分理解“用戶協(xié)議”和“隱私政策”各條款,包括但不限于:" + "為了向您提供交易相關(guān)基本功能,我們會收集、使用必要的信息。你可閱讀" + "《用戶協(xié)議》" + "和" + "《隱私政策》" + "了解詳細(xì)信息。如您同意,請點擊“同意”接受我們的服務(wù)。"; SpannableStringBuilder ssb = new SpannableStringBuilder(); ssb.append(str); //第一個出現(xiàn)的位置 final int start = str.indexOf("《"); ssb.setSpan(new ClickableSpan() {
          @Override public void onClick(View widget) { //用戶服務(wù)協(xié)議點擊事件 Bundle bundle = new Bundle(); bundle.putString("title", "用戶協(xié)議"); bundle.putInt("showType", 0); bundle.putString("content", MyApplication.getDataIndex().get("SYSUSER_PROTOL")); go(WebActivity.class, bundle); }
          @Override public void updateDrawState(TextPaint ds) { super.updateDrawState(ds); //設(shè)置文件顏色 ds.setColor(getResources().getColor(R.color.colorMain)); // 去掉下劃線 ds.setUnderlineText(false); }
          }, start, start + 6, 0);
          //最后一個出現(xiàn)的位置 final int end = str.lastIndexOf("《"); ssb.setSpan(new ClickableSpan() {
          @Override public void onClick(View widget) { //隱私協(xié)議點擊事件 Bundle bundle = new Bundle(); bundle.putString("title", "隱私政策"); bundle.putInt("showType", 0); bundle.putString("content", MyApplication.getDataIndex().get("SYSUSER_HIDE_PROTOL")); go(WebActivity.class, bundle); }
          @Override public void updateDrawState(TextPaint ds) { super.updateDrawState(ds); //設(shè)置文件顏色 ds.setColor(getResources().getColor(R.color.colorMain)); // 去掉下劃線 ds.setUnderlineText(false); }
          }, end, end + 6, 0); content.setMovementMethod(LinkMovementMethod.getInstance()); content.setText(ssb, TextView.BufferType.SPANNABLE);
          mDialog.findViewById(R.id.tv_cancel).setOnClickListener(v -> { mDialog.dismiss(); finish(); }); mDialog.findViewById(R.id.tv_sure).setOnClickListener(v -> { mDialog.dismiss(); //更改狀態(tài),同意下次進(jìn)入軟件則不再彈出彈框 MyApplication.setIsNew("not"); }); }

          最后將dialog的樣式附上

              <style name="Teldialog" parent="@android:style/Theme.Dialog">        <item name="android:windowBackground">@color/windowTransactionitem>        <item name="android:windowFrame">@nullitem>        <item name="android:windowNoTitle">trueitem>        <item name="android:windowIsFloating">trueitem>        <item name="android:gravity">bottomitem>        <item name="android:windowIsTranslucent">trueitem>        <item name="android:windowCloseOnTouchOutside">trueitem>        <item name="android:windowContentOverlay">@nullitem>        <item name="android:windowAnimationStyle">@android:style/Animation.Dialogitem>        <item name="android:backgroundDimEnabled">trueitem>style>

          到這里就結(jié)束啦。
          瀏覽 58
          點贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  影音先锋色网 | 一区二区网站 | 免费看黄色的视频 | 奇米无码在线 | 欧美成人影视在线 |