中国移动一键登录 —— SDK5.8.1使用setAuthContentView方法开发

代码 代码 1827 人阅读 | 0 人回复

<
此文出要处理部门接进者没有明白怎样设置面击变乱和设置的View出有战料想的一样齐屏成绩。
目次
1. 筹办事情
2. setAuthContentView的挪用
3. 运转结果图

1. 筹办事情

1.1 曾经接进好SDK,利用默许设置可以运转。
1.2 按照公司产品请求调好SDK "本机号码一键登录" 按钮、号码栏、和谈栏地位。
2. setAuthContentView的挪用

2.1 筹办好要增加到SDK受权页的XML文件
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.     android:layout_width="match_parent"
  4.     android:layout_height="match_parent">
  5.     <TextView
  6.         android:layout_width="wrap_content"
  7.         android:layout_height="wrap_content"
  8.         android:layout_alignParentEnd="true"
  9.         android:layout_marginTop="8dp"
  10.         android:layout_marginEnd="20dp"
  11.         android:text="出门左转新东圆烹调黉舍"
  12.         android:textColor="@color/red"
  13.         android:textSize="16sp" />
  14.     <TextView
  15.         android:layout_width="wrap_content"
  16.         android:layout_height="wrap_content"
  17.         android:layout_marginStart="50dp"
  18.         android:layout_marginTop="100dp"
  19.         android:text="欢送登录蓝翔发掘机黉舍"
  20.         android:textColor="@color/red"
  21.         android:textSize="18sp" />
  22.     <TextView
  23.         android:layout_width="wrap_content"
  24.         android:layout_height="wrap_content"
  25.         android:layout_marginStart="50dp"
  26.         android:layout_marginTop="170dp"
  27.         android:text="本机号码"
  28.         android:textColor="@color/red"
  29.         android:textSize="12sp" />
  30.     <TextView
  31.         android:layout_width="wrap_content"
  32.         android:layout_height="wrap_content"
  33.         android:layout_alignParentEnd="true"
  34.         android:layout_marginTop="190dp"
  35.         android:layout_marginEnd="16dp"
  36.         android:text="面击进进富婆通信录"
  37.         android:textColor="@color/red" />
  38.     <Button
  39.         android:id="@+id/btn_test_error"
  40.         android:layout_width="match_parent"
  41.         android:layout_height="wrap_content"
  42.         android:layout_centerHorizontal="true"
  43.         android:layout_centerVertical="true"
  44.         android:layout_marginStart="16dp"
  45.         android:layout_marginEnd="16dp"
  46.         android:text="中国挪动"
  47.         android:textColor="@color/red"
  48.         android:textSize="18sp" />
  49.     <TextView
  50.         android:id="@+id/tv_s"
  51.         android:layout_width="wrap_content"
  52.         android:layout_height="wrap_content"
  53.         android:layout_below="@+id/btn_test_error"
  54.         android:layout_marginTop="45dp"
  55.         android:layout_toStartOf="@+id/tv_z"
  56.         android:background="@color/blue"
  57.         android:padding="8dp"
  58.         android:text="神"
  59.         android:textColor="@color/white"
  60.         android:textSize="24sp" />
  61.     <TextView
  62.         android:id="@+id/tv_z"
  63.         android:layout_width="wrap_content"
  64.         android:layout_height="wrap_content"
  65.         android:layout_below="@+id/btn_test_error"
  66.         android:layout_marginStart="16dp"
  67.         android:layout_marginTop="45dp"
  68.         android:layout_toStartOf="@+id/tv_x"
  69.         android:background="@color/blue"
  70.         android:padding="8dp"
  71.         android:text="州"
  72.         android:textColor="@color/white"
  73.         android:textSize="24sp" />
  74.     <TextView
  75.         android:id="@+id/tv_x"
  76.         android:layout_width="wrap_content"
  77.         android:layout_height="wrap_content"
  78.         android:layout_below="@+id/btn_test_error"
  79.         android:layout_marginStart="16dp"
  80.         android:layout_marginTop="45dp"
  81.         android:layout_toStartOf="@+id/hold_view"
  82.         android:background="@color/blue"
  83.         android:padding="8dp"
  84.         android:text="止"
  85.         android:textColor="@color/white"
  86.         android:textSize="24sp" />
  87.     <View
  88.         android:id="@+id/hold_view"
  89.         android:layout_width="1dp"
  90.         android:layout_height="1dp"
  91.         android:layout_below="@+id/btn_test_error"
  92.         android:layout_centerHorizontal="true"
  93.         android:layout_marginStart="8dp"
  94.         android:layout_marginTop="45dp"
  95.         android:layout_marginEnd="8dp" />
  96.     <TextView
  97.         android:id="@+id/tv_w"
  98.         android:layout_width="wrap_content"
  99.         android:layout_height="wrap_content"
  100.         android:layout_below="@+id/btn_test_error"
  101.         android:layout_marginTop="45dp"
  102.         android:layout_toEndOf="@+id/hold_view"
  103.         android:background="@color/blue"
  104.         android:padding="8dp"
  105.         android:text="我"
  106.         android:textColor="@color/white"
  107.         android:textSize="24sp" />
  108.     <TextView
  109.         android:id="@+id/tv_k"
  110.         android:layout_width="wrap_content"
  111.         android:layout_height="wrap_content"
  112.         android:layout_below="@+id/btn_test_error"
  113.         android:layout_marginStart="16dp"
  114.         android:layout_marginTop="45dp"
  115.         android:layout_toEndOf="@+id/tv_w"
  116.         android:background="@color/blue"
  117.         android:padding="8dp"
  118.         android:text="看"
  119.         android:textColor="@color/white"
  120.         android:textSize="24sp" />
  121.     <TextView
  122.         android:id="@+id/tv_xi"
  123.         android:layout_width="wrap_content"
  124.         android:layout_height="wrap_content"
  125.         android:layout_below="@+id/btn_test_error"
  126.         android:layout_marginStart="16dp"
  127.         android:layout_marginTop="45dp"
  128.         android:layout_toEndOf="@+id/tv_k"
  129.         android:background="@color/blue"
  130.         android:padding="8dp"
  131.         android:text="止"
  132.         android:textColor="@color/white"
  133.         android:textSize="24sp" />
  134.    
  135. </RelativeLayout>
复造代码
AS预览以下图所示:
214335drt67rm7knh356ht.jpg

2.2 经由过程LayoutInflater天生setAuthContentView办法所需的View,并设置指定View的面击变乱。
  1. val contentView: View = LayoutInflater.from(this@MainActivity)
  2.     .inflate(R.layout.test_error, null)
  3.     .apply {
  4.             //经由过程findViewById获得到要设置面击变乱的View并设置面击变乱。
  5.             this.findViewById<Button>(R.id.btn_test_error).setOnClickListener {
  6.             
  7.             //开辟者本人的营业,那里弹出一个Toast
  8.             Toast.makeText(this@MainActivity,"面击了“中国挪动”按钮", Toast.LENGTH_SHORT).show()
  9.             
  10.             }
  11.             
  12.             //为何要设置LayoutParams,请浏览LayoutInflater源码。
  13.             this.layoutParams = RelativeLayout.LayoutParams(
  14.                  RelativeLayout.LayoutParams.MATCH_PARENT,
  15.                  RelativeLayout.LayoutParams.MATCH_PARENT)
  16.     }
  17. mHelper?.authThemeConfig = AuthThemeConfig.Builder().apply {
  18.    
  19.     this.setAuthContentView(contentView)
  20.     this.setLogBtn(-1, 45)
  21.    
  22.     this.setLogBtnMargin(30, 30)
  23.     this.setLogBtnClickListener(object : LoginClickListener {
  24.     override fun onLoginClickStart(p0: Context?, p1: JSONObject?) {
  25.          MyLog.e("======开端面击=====")
  26.      }
  27.     override fun onLoginClickComplete(p0: Context?, p1: JSONObject?) {
  28.           MyLog.e("=====面击完毕=====")
  29.      }
  30.    })
  31.     this.setStatusBar(0xFFFFFFFF.toInt(), true)
  32.     this.setCheckTipText("")
  33.    
  34.     this.setNumberOffsetX(50)
  35.     this.setPrivacyAlignment(
  36.                     "脚机号登录即暗示您赞成\n免责声名及" + AuthThemeConfig.PLACEHOLDER2,
  37.                     "免责声名",
  38.                     "https://www.cmpassport.com",null,null
  39.          )
  40.     this.setPrivacyText(
  41.                     14,
  42.                     ContextCompat.getColor(this@MainActivity, R.color.blue),
  43.                     ContextCompat.getColor(this@MainActivity, R.color.red),
  44.                     true
  45.          )
  46.     this.setPrivacyMargin(0, 0)
  47. }.build()
复造代码
3. 运转结果图

214335u9z9n9t7919l9nt6.gif


 PS:闭于LayoutInflate的inflate(R.layout.您的xml, null)创立出去的View为何会不克不及齐屏的成绩假如以为寓目源码易度较年夜能够举办debug阐发:
214336s3iiu1i3141dn411.jpg






免责声明:假如进犯了您的权益,请联络站少,我们会实时删除侵权内乱容,感谢协作!
1、本网站属于个人的非赢利性网站,转载的文章遵循原作者的版权声明,如果原文没有版权声明,按照目前互联网开放的原则,我们将在不通知作者的情况下,转载文章;如果原文明确注明“禁止转载”,我们一定不会转载。如果我们转载的文章不符合作者的版权声明或者作者不想让我们转载您的文章的话,请您发送邮箱:Cdnjson@163.com提供相关证明,我们将积极配合您!
2、本网站转载文章仅为传播更多信息之目的,凡在本网站出现的信息,均仅供参考。本网站将尽力确保所提供信息的准确性及可靠性,但不保证信息的正确性和完整性,且不对因信息的不正确或遗漏导致的任何损失或损害承担责任。
3、任何透过本网站网页而链接及得到的资讯、产品及服务,本网站概不负责,亦不负任何法律责任。
4、本网站所刊发、转载的文章,其版权均归原作者所有,如其他媒体、网站或个人从本网下载使用,请在转载有关文章时务必尊重该文章的著作权,保留本网注明的“稿件来源”,并自负版权等法律责任。
回复 关闭延时

使用道具 举报

 
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则