自定义底部菜单栏按钮
语聊房 UIKit(Live Audio Room Kit) 支持自定义调整菜单栏的按钮,支持删除默认按钮或添加自定义按钮。您可以删除默认按钮或添加自定义按钮。如果需要,您可以配置bottomMenuBarConfig:
hostButtons
:使用此选项为房主(主持人)设置预制的按钮。speakerButtons
:使用此选项为发言人设置预制的按钮。audienceButtons
:使用此选项为观众设置预制的按钮。
menuBarButtonsMaxCount
:菜单栏可以显示的按钮的最大数量,支持范围设置[1, 5],默认值是 5。
showInRoomMessageButton
:是否显示消息按钮,默认显示。
如果内置按钮和自定义按钮的总数不超过menuBarButtonsMaxCount
个,所有按钮都将正常显示。
若按钮数超过 5 个,超出的其他按钮将隐藏在(⋮)按钮中。单击此按钮将弹出底部面板以显示其他所有按钮。以下是实际效果和参考代码:
Java
Kotlin
public class LiveAudioRoomActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_call);
addFragment();
}
public void addFragment() {
long appID = yourAppID; // 替换为您的 AppID,请从 ZEGO 控制台获取
String appSign = yourAppSign; // 替换为您的 AppSign,请从 ZEGO 控制台获取
String userID = yourUserID; // 替换为您的 UserID
String userName = yourUserName; // 替换为您的 UserName
boolean isHost = getIntent().getBooleanExtra("host", false);
String roomID = getIntent().getStringExtra("roomID");
ZegoUIKitPrebuiltLiveAudioRoomConfig config;
if (isHost) {
config = ZegoUIKitPrebuiltLiveAudioRoomConfig.host();
} else {
config = ZegoUIKitPrebuiltLiveAudioRoomConfig.audience();
}
config.bottomMenuBarConfig.hostButtons = Arrays.asList(ZegoMenuBarButtonName.TOGGLE_MICROPHONE_BUTTON, ZegoMenuBarButtonName.SHOW_MEMBER_LIST_BUTTON);
config.bottomMenuBarConfig.speakerButtons = Arrays.asList(ZegoMenuBarButtonName.TOGGLE_MICROPHONE_BUTTON, ZegoMenuBarButtonName.SHOW_MEMBER_LIST_BUTTON);
config.bottomMenuBarConfig.audienceButtons = Arrays.asList(ZegoMenuBarButtonName.SHOW_MEMBER_LIST_BUTTON);
ZegoUIKitPrebuiltLiveAudioRoomFragment fragment = ZegoUIKitPrebuiltLiveAudioRoomFragment.newInstance(appID, appSign, userID, userName, roomID, config);
getSupportFragmentManager().beginTransaction()
.replace(R.id.fragment_container, fragment)
.commitNow();
}
}
1
class LiveAudioRoomActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_live)
addFragment()
}
private fun addFragment() {
val appID: Long = yourAppID // 替换为您的 AppID,请从 ZEGO 控制台获取
val appSign = yourAppSign // 替换为您的 AppSign,请从 ZEGO 控制台获取
val userID = YourUserID // 替换为您的 UserID
val userName = YourUserName // 替换为您的 UserName
val isHost = intent.getBooleanExtra("host", false)
val roomID = intent.getStringExtra("roomID")
val config: ZegoUIKitPrebuiltLiveAudioRoomConfig = if (isHost) {
ZegoUIKitPrebuiltLiveAudioRoomConfig.host()
} else {
ZegoUIKitPrebuiltLiveAudioRoomConfig.audience()
}
config.bottomMenuBarConfig.hostButtons = Arrays.asList(ZegoMenuBarButtonName.TOGGLE_MICROPHONE_BUTTON, ZegoMenuBarButtonName.SHOW_MEMBER_LIST_BUTTON)
config.bottomMenuBarConfig.speakerButtons = Arrays.asList(ZegoMenuBarButtonName.TOGGLE_MICROPHONE_BUTTON, ZegoMenuBarButtonName.SHOW_MEMBER_LIST_BUTTON)
config.bottomMenuBarConfig.audienceButtons = Arrays.asList(ZegoMenuBarButtonName.SHOW_MEMBER_LIST_BUTTON)
val fragment = ZegoUIKitPrebuiltLiveAudioRoomFragment.newInstance(appID, appSign, userID, userName, roomID, config)
supportFragmentManager.beginTransaction()
.replace(R.id.fragment_container, fragment)
.commitNow()
}
}
1
此外,您也可以通过以下方法,实现相同的效果:addButtonToMenuBar
和 clearBottomBarExtendButtons
。
Java
Kotlin
class ZegoUIKitPrebuiltLiveAudioRoomFragment{
//...
void addButtonToMenuBar(List<View> widgets, ZegoLiveAudioRoomRole role);
void clearBottomBarExtendButtons(ZegoLiveAudioRoomRole role);
//...
}
1
class ZegoUIKitPrebuiltLiveAudioRoomFragment{
//...
fun addButtonToMenuBar(widgets: List<View>?, role: ZegoLiveAudioRoomRole?)
fun clearBottomBarExtendButtons(role: ZegoLiveAudioRoomRole?)
//...
}
1