【问题标题】:Adding a Button in the Status Bar在状态栏中添加按钮
【发布时间】:2020-01-24 14:07:26
【问题描述】:

我正在开发一个 Android 应用程序,我想在状态栏中添加一个电话按钮。我可以在状态栏中添加电话按钮吗?

我想添加一个按钮,如上图所示。我尝试处理通知,但通知图标大小太小。我该怎么做?有什么想法吗?

【问题讨论】:

    标签: android statusbar


    【解决方案1】:

    我认为在状态栏中放置一个按钮违反了设计准则,因为它应该只包含通知和系统图标。见https://material.io/design/platform-guidance/android-bars.html#status-bar。

    尝试使用提醒通知 (https://developer.android.com/guide/topics/ui/notifiers/notifications.html)。 您可以将按钮放在通知的操作区域(https://material.io/design/platform-guidance/android-notifications.html#anatomy-of-a-notification)。

    【讨论】:

    • 感谢您的回复。系统电话应用程序正在执行此操作。它在 System Phone/Calling 应用中是如何工作的?
    • @SushilSolanki 试试这个:v4all123.blogspot.com/2018/11/…
    【解决方案2】:

    看起来您需要带有通知图标的前台服务 - here

    前台服务示例代码 -

    public class ExampleService extends Service {
    
    @Override
    public void onCreate() {
        super.onCreate();
    }
    
    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        String input = intent.getStringExtra("inputExtra");
    
        Intent notificationIntent = new Intent(this, MainActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(this,
                0, notificationIntent, 0);
    
        Notification notification = new NotificationCompat.Builder(this, CHANNEL_ID)
                .setContentTitle("Example Service")
                .setContentText(input)
                .setSmallIcon(R.drawable.ic_android)
                .setContentIntent(pendingIntent)
                .build();
    
        startForeground(1, notification);
    
        //do heavy work on a background thread
        //stopSelf();
    
        return START_NOT_STICKY;
    }
    
    @Override
    public void onDestroy() {
        super.onDestroy();
    }
    
    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }
    

    }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多