tt.createMoreGamesButton

2020-02-15 02:15 更新
基礎(chǔ)庫(kù) 1.23.0 開(kāi)始支持本方法,低版本需做兼容處理。

創(chuàng)建更多游戲按鈕。用戶(hù)點(diǎn)擊該按鈕后,會(huì)彈出一個(gè)固定樣式的彈窗,彈窗中包含預(yù)先配置的小游戲列表。


參數(shù)

Object 類(lèi)型,屬性如下:

屬性類(lèi)型默認(rèn)值必填描述
typestring按鈕的類(lèi)型,取值 image 或 text。image 對(duì)應(yīng)圖片按鈕,text 對(duì)應(yīng)文本按鈕
imagestring按鈕的背景圖片,type 為 image 時(shí)必填。僅支持本地圖片,目錄包括代碼包目錄、臨時(shí)文件目錄和本地用戶(hù)目錄
textstring更多游戲按鈕上的文本內(nèi)容, type 為 text 時(shí)有效
styleobject按鈕的樣式
appLaunchOptionsArray<object>小游戲的啟動(dòng)參數(shù)
onNavigateToMiniGamefunction跳轉(zhuǎn)小游戲時(shí)的回調(diào)函數(shù)

appLaunchOptions 參數(shù)說(shuō)明

Array<object> 類(lèi)型,結(jié)構(gòu)如下:

屬性類(lèi)型默認(rèn)值必填說(shuō)明
appIdstring要打開(kāi)的小游戲 appId
querystring查詢(xún)字符串,必須是 key1=val1&key2=val2 的格式??赏ㄟ^(guò) tt.getLaunchOptionSync() 或 tt.onShow() 獲取啟動(dòng)參數(shù)中的 query
extraDataobject需要傳遞給目標(biāo)小游戲的數(shù)據(jù)??赏ㄟ^(guò) tt.getLaunchOptionsSync() 或 tt.onShow() 返回的 referrerInfo 字段獲取對(duì)應(yīng)數(shù)據(jù)

onNavigateToMiniGame 回調(diào)函數(shù)參數(shù)

Object 類(lèi)型,屬性如下:

屬性類(lèi)型說(shuō)明
errCodenumber跳轉(zhuǎn)錯(cuò)誤碼
errMsgstring跳轉(zhuǎn)失敗時(shí)的提示信息

errCode 取值說(shuō)明

說(shuō)明
0跳轉(zhuǎn)成功
1跳轉(zhuǎn)失敗
2用戶(hù)取消

style 參數(shù)說(shuō)明

屬性類(lèi)型默認(rèn)值必填說(shuō)明
leftnumber左上角橫坐標(biāo)
topnumber左上角縱坐標(biāo)
widthnumber寬度
heightnumber高度
backgroundColorstring背景顏色
borderColorstring邊框顏色
borderWidthnumber邊框?qū)挾?/td>
borderRadiusnumber邊框圓角
textAlignstring文本的水平居中方式
fontSizenumber字號(hào)
lineHeightnumber文本的行高
textColorstring文本顏色

style.textAlign 屬性合法值

說(shuō)明
left居左
center居中
right居右


返回

返回一個(gè) MoreGamesButton 對(duì)象


示例

const btn = tt.createMoreGamesButton({
  type: "image",
  image: "images/more_games_btn.png",
  style: {
    left: 20,
    top: 40,
    width: 150,
    height: 40,
    lineHeight: 40,
    backgroundColor: "#ff0000",
    textColor: "#ffffff",
    textAlign: "center",
    fontSize: 16,
    borderRadius: 4,
    borderWidth: 1,
    borderColor: "#ff0000"
  },
  appLaunchOptions: [
    {
      appId: "ttXXXXXX",
      query: "foo=bar&baz=qux",
      extraData: {}
    }
    // {...}
  ],
  onNavigateToMiniGame(res) {
    console.log("跳轉(zhuǎn)其他小游戲", res);
  }
});

btn.onTap(() => {
  console.log("點(diǎn)擊更多游戲");
});


以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)