android - 如何设置或更改通知按钮位置
问题描述
找不到有关按钮定位的任何信息。我发现不同的设备以不同的方式显示按钮(左\中\右)
我可以从我的 Xamarin 项目中提供一些代码,但 Kotlin\Java 代码应该几乎相同
var notificationBuilder = new NotificationCompat.Builder(Application.Context, ChannelId)
.SetSmallIcon(ApplicationContext.ApplicationInfo.Icon)
.SetContentTitle("title")
.SetContentText("message")
.SetAutoCancel(true)
.SetStyle(new NotificationCompat.BigTextStyle().BigText(message))
.SetColor(Resource.Color.orange)
.SetContentIntent(contentIntent);
var buttonIntent = new Intent(ApplicationContext, typeof(NotificationReceiver));
buttonIntent.PutExtra(NotificationConstants.SelectedActionKey, selectedAction);
var pendingIntent = PendingIntent.GetBroadcast(ApplicationContext, requestCode, buttonIntent, PendingIntentFlags.UpdateCurrent);
notificationBuilder.AddAction(0, "cool button", pendingIntent),
解决方案
您将无法选择默认操作的显示方式。但是您可以改为自定义视图。
RemoteViews remoteViews = new RemoteViews("com.companyname.NotificationChannelsDemo", Resource.Layout.layout1);
var builder = new NotificationCompat.Builder(this, CHANNEL_ID2)
.SetCustomContentView(remoteViews).
.........
com.companyname.NotificationChannelsDemo
是你的包名。
Resource.Layout.layout1
是您的自定义视图的布局。您可以在此布局中设置按钮位置。
推荐阅读
- javascript - 将对象转换为数组
- python - Celery/Redis 无限加载
- ios - “UNLocationNotificationTrigger”在 Mac Catalyst 中不可用
- mysql - Spring Data Jpa 不在新线程中保存实体
- c# - 条件 == null 和 != null 返回同一行
- c# - 如何在不使用纯文本的情况下连接到 mysql?
- python - 为什么我在使用 ResNet50 进行迁移学习时会出错?
- firebase - Firestore:返回的数据没有正确的收藏项状态 True 或 False
- c++ - 使用自定义 IDocHostUIHandler 和关闭窗口时崩溃
- swift - 点击展开 UITableViewCell(自定义) - 自动调整单元格 - 一些问题