Android 媒体音量控制器(无论它叫什么)的自定义主题?

发布于 2024-09-26 07:34:45 字数 277 浏览 12 评论 0原文

我正在尝试自定义媒体音量控制器的主题(我不知道它叫什么,只是尝试命名它)。它类似于一个标题为“媒体音量”的 Toast,当我们在游戏中按下音量按钮(+ 和 -)时,就会出现该标题。但我不知道它是哪个View,或者它是一个Toast、一个Dialog。就我所尝试的而言,我找不到任何提及它的内容。仅Activity.setVolumeControlStream(AudioManager.STREAM_MUSIC) 在您的活动中启用它,仅此而已。如果有人知道如何自定义它,或者只是它的名称,请帮助我! 谢谢。

I'm trying custom the theme of Media Volume Controller (I don't know what it's called, just try to name it). It's something like a Toast with "Media Volume" title which appears when we press volume buttons (+ and -) in games. But I don't know which View it's, or it's a Toast, a Dialog. So far as I try, I could not find anything which refers it. Only Activity.setVolumeControlStream(AudioManager.STREAM_MUSIC)
to enable it in your Activity, and nothing more. If someone know how to custom it, or just it's name, please help me!
Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你怎么敢 2024-10-03 07:34:45

抱歉我对你的问题的误解。

我认为您可以自定义“媒体音量控制器”的方法是自己控制音量并显示您的自定义视图(或Toast)。因为“Media Volume”Toast(它是一个Toast,参见VolumePanel.onShowVolumeChanged )由 Android 系统创建并显示,您无法自定义。

这是可能解决您的问题的示例代码:

public boolean onKeyDown(int keyCode, KeyEvent event) {
    AudioManager am = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
    if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
        // Or use adjustStreamVolume method.
        am.adjustVolume(AudioManager.ADJUST_RAISE, AudioManager.FLAG_PLAY_SOUND);
        Toast.makeText(this, "Volume up", Toast.LENGTH_SHORT).show();
        return false;
    } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
        // Or use adjustStreamVolume method.
        am.adjustVolume(AudioManager.ADJUST_LOWER, AudioManager.FLAG_PLAY_SOUND);
        Toast.makeText(this, "Volume down", Toast.LENGTH_SHORT).show();
        return false;
    }
    return super.onKeyDown(keyCode, event);
}

Sorry for my misunderstanding of your question.

I think the way you can customize "Media Volume Controller" is control volume yourself and show your customize view(or Toast). Because the "Media Volume" Toast(It is a Toast, see the source code of VolumePanel.onShowVolumeChanged ) is created and shown by android system which you cannot customize.

Here is the sample code which might solve your problem:

public boolean onKeyDown(int keyCode, KeyEvent event) {
    AudioManager am = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
    if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
        // Or use adjustStreamVolume method.
        am.adjustVolume(AudioManager.ADJUST_RAISE, AudioManager.FLAG_PLAY_SOUND);
        Toast.makeText(this, "Volume up", Toast.LENGTH_SHORT).show();
        return false;
    } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
        // Or use adjustStreamVolume method.
        am.adjustVolume(AudioManager.ADJUST_LOWER, AudioManager.FLAG_PLAY_SOUND);
        Toast.makeText(this, "Volume down", Toast.LENGTH_SHORT).show();
        return false;
    }
    return super.onKeyDown(keyCode, event);
}
柠檬心 2024-10-03 07:34:45

您可以覆盖游戏 Activity 的 onKeyDown。并根据刚刚按下的键显示“Toast”。当在 Activity 中按下某个键时,将调用 onKeyDown 方法。以下是示例代码:

public boolean onKeyDown(int keyCode, KeyEvent event)  {
    if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
        // show volumn up toast
    } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
        // show volumn down toast
    }
    return super.onKeyDown(keyCode, event);
}

You can override the onKeyDown of your game Activity. And show the "Toast" according to the key just pressed. onKeyDown method will be called when a key was pressed down in your Activity. Following is sample code:

public boolean onKeyDown(int keyCode, KeyEvent event)  {
    if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
        // show volumn up toast
    } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
        // show volumn down toast
    }
    return super.onKeyDown(keyCode, event);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文