# qq.createAddFriendButton

# AddFriendButton qq.createAddFriendButton(Object object)

创建打开添加好友页面的按钮

# 参数

# Object object
属性 类型 默认值 必填 说明
type string 是 按钮的类型
text string 否 按钮上的文本,仅当 type 为 text 时有效
image string 否 按钮的背景图片,仅当 type 为 image 时有效
style Object 是 按钮的样式
openid string 是 好友的openid

type 的合法值

值 说明
text 可以设置背景色和文本的按钮
image 只能设置背景贴图的按钮,背景贴图会直接拉伸到按钮的宽高

style 的结构

属性 类型 默认值 必填 说明
left number 是 左上角横坐标
top number 是 左上角纵坐标
width number 是 宽度
height number 是 高度
backgroundColor string 是 背景颜色。格式为 6位/8位 16进制数。
borderColor string 是 边框颜色。格式为 6位/8位 16进制数。
borderWidth number 是 边框宽度
borderRadius number 是 边框圆角
color string 是 文本的颜色。格式为 6位 16进制数。
textAlign string 是 文本的水平居中方式
fontSize number 是 字号
lineHeight number 是 文本的行高

style.textAlign 的合法值

值 说明
left 居左
center 居中
right 居右

# 返回值

# AddFriendButton

# 示例代码

const button = qq.createAddFriendButton({
  type: 'text',
  text: '添加好友',
  style: {
    left: 10,
    top: 76,
    width: 200,
    height: 40,
    lineHeight: 40,
    backgroundColor: '#ff0000',
    color: '#ffffff',
    textAlign: 'center',
    fontSize: 16,
    borderRadius: 4
  }
})
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

# 属性

# string openid

好友的openid

# string type

按钮的类型

type 的合法值

值 说明
text 可以设置背景色和文本的按钮
image 只能设置背景贴图的按钮,背景贴图会直接拉伸到按钮的宽高
# string text

按钮上的文本,仅当 type 为 text 时有效

# string image

按钮的背景图片,仅当 type 为 image 时有效

# Object style

按钮的样式

属性 类型 说明
left number 左上角横坐标
top number 左上角纵坐标
width number 宽度
height number 高度
backgroundColor string 背景颜色。格式为 6位/8位 16进制数。
borderColor string 边框颜色。格式为 6位/8位 16进制数。
borderWidth number 边框宽度
borderRadius number 边框圆角
color string 文本的颜色。格式为 6位 16进制数。
textAlign string 文本的水平居中方式
fontSize number 字号
lineHeight number 文本的行高

style.textAlign 的合法值

值 说明
left 居左
center 居中
right 居右

# 方法

# AddFriendButton.show()

显示添加好友页面按钮

# AddFriendButton.hide()

隐藏添加好友页面按钮。

# AddFriendButton.destroy()

销毁添加好友页面按钮

# AddFriendButton.onTap(function callback)

监听添加好友页面按钮的点击事件,对方需要通过该小游戏进行授权,允许被加好友后才能调用成功用户授权

# AddFriendButton.offTap(function callback)

取消监听添加好友页面按钮的点击事件

# .destroy

# AddFriendButton.destroy()

销毁添加好友页面按钮

# .hide

# AddFriendButton.hide()

隐藏添加好友页面按钮。

# .offTap

# AddFriendButton.offTap(function callback)

取消监听添加好友页面按钮的点击事件

# 参数

# function callback

添加好友页面按钮的点击事件的回调函数

# .onTap

# AddFriendButton.onTap(function callback)

监听添加好友页面按钮的点击事件

# 参数

# function callback

添加好友页面按钮的点击事件的回调函数

# .show

# AddFriendButton.show()

显示添加好友页面按钮

# 注意事项

  1. 被添加者调用qq.authorize({scope: "setting.addFriend"})授权允许被添加好友,详见用户授权。
  2. 添加未授权用户,AddFriendButton.onTap会返回添加好友失败,未授权的错误提示。