可以使用 Intent.createChooser() 的方法来创建 Intent,并传入想要的 Sting 作为标题。
以wallpaper 选择框为例,当在Launcher workspace的空白区域上长按,会弹出wallpaper的选择框,选择框的标题为”Choose wallpaper from”,如下:
private void startWallpaper() {
showWorkspace(true);
final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Intent chooser = Intent.createChooser(pickWallpaper, getText(R.string.chooser_wallpaper));
// NOTE: Adds a configure option to the chooser if the wallpaper supports it
startActivityForResult(chooser, REQUEST_PICK_WALLPAPER);
}
其中,R.string.chooser_wallpaper对应的字串内容就是”Choose wallpaper from”,定义在Launcher2的Strings.xml中
以wallpaper 选择框为例,当在Launcher workspace的空白区域上长按,会弹出wallpaper的选择框,选择框的标题为”Choose wallpaper from”,如下:
private void startWallpaper() {
showWorkspace(true);
final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Intent chooser = Intent.createChooser(pickWallpaper, getText(R.string.chooser_wallpaper));
// NOTE: Adds a configure option to the chooser if the wallpaper supports it
startActivityForResult(chooser, REQUEST_PICK_WALLPAPER);
}
其中,R.string.chooser_wallpaper对应的字串内容就是”Choose wallpaper from”,定义在Launcher2的Strings.xml中
本文详细介绍了如何使用Intent.createChooser()方法在Android应用中创建意图选择框,以实现用户选择特定功能的目的。通过示例代码,展示了如何设置标题、启动选择框并处理用户选择。
9775

被折叠的 条评论
为什么被折叠?



