获取Android系统重音(Android 10系统颜色重音)

发布于 01-17 10:53 字数 685 浏览 5 评论 0原文

这个问题应该很简单,但我没有找到答案。我有一个具有可选口音的应用程序,并且我正在尝试添加一个使用Android System Accent的选项(如割草机这样的应用程序具有这样的选择)。在系统重音的样式中,我尝试以各种可能的方式获得这种口音:

?android:coloraccent

?android:atter/attr/coloraccent

?attr/coloraccent

,这是一种样式:

<style name="AppTheme.systemAccent" parent="AppTheme">
    <item name="colorAccent">???</item>
</style>

似乎没有任何作用,应用程序崩溃了,但是我敢肯定这是可能的。当我使用正常颜色时,重音选择正常。我在哪里错了?

编辑:要清楚,我正在尝试获得系统强调颜色,即设置中使用的系统宽颜色,通知面板等。现在可以在Android 10中选择该颜色,并且可以在ROM中像氧OS一样选择。假设我在 Android 10设备上选择了“设置”中的红色重音。我想在我的应用中得到这个红色的口音

This question should be simple, but i didn't find an answer. I have an app with selectable accent, and i'm trying to add an option to use the android system accent (apps like Lawnchair have such an option). In the style for the system accent, i tried to get this accent in every way possible:

?android:colorAccent

?android:attr/colorAccent

?attr/colorAccent

And this is the style:

<style name="AppTheme.systemAccent" parent="AppTheme">
    <item name="colorAccent">???</item>
</style>

Nothing seems to work and the app crashes, but i'm certain that this is possible. The accent selection, when i use normal colors, works fine. Where am i wrong?

EDIT: Just to be clear, i'm trying to get the system accent color, i.e. the system wide color used in settings, notification panel and so on. This color is now selectable in Android 10 and was selectable before in rom like the Oxygen OS. Let's say i select a red accent in settings->customization on my Android 10 device. I want to get this red accent in my app

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

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

发布评论

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

评论(4

静待花开 2025-01-24 10:53:57

您可以通过编程方式获取它:

TypedValue typedValue = new TypedValue();
ContextThemeWrapper contextThemeWrapper = new ContextThemeWrapper(this,
     android.R.style.Theme_DeviceDefault);
contextThemeWrapper.getTheme().resolveAttribute(android.R.attr.colorAccent,
     typedValue, true);
int color = typedValue.data; 

要明确我指的是Android Q System color Accent:

“在此处输入图像说明”

You can get it programmatically:

TypedValue typedValue = new TypedValue();
ContextThemeWrapper contextThemeWrapper = new ContextThemeWrapper(this,
     android.R.style.Theme_DeviceDefault);
contextThemeWrapper.getTheme().resolveAttribute(android.R.attr.colorAccent,
     typedValue, true);
int color = typedValue.data; 

Just to be clear I am referring to the Android Q System color accent:

enter image description here
enter image description here

我是有多爱你 2025-01-24 10:53:57

好的。我进行了一些密集的研究和反复试验。之后,我发现我可以访问私有属性@*android:color/accent_device_default_light但是如果您将活动的父类从appcompatactivity更改为活动,这是可能的,因为AppCompat无法使用这个私人财产。此外,不建议使用私人物业,因为它们可能会在将来被删除或更改。

Okay. I did some intensive research and trial and error. After that I found out, that I could access a private property @*android:color/accent_device_default_light. BUT this is just possible if you change your parent class for the activity from AppCompatActivity to Activity because the AppCompat can't set up the toolbar with this private property. Further it's not recommended to use private properties because they are likely to get deleted or changed in the future.

很酷又爱笑 2025-01-24 10:53:57

您可以使用设置(或类似的应用程序)来列举它。查找安全表下方的sysui_type_accent_color键。您也可以通过adb shell通过busybox content通过adb shell进行编程执行此操作。

You can use SetEdit (or similar application) to enumerate it. Look for the sysui_type_accent_color key under the Secure table. You can also do this programatically, if I recall correctly, through adb shell via busybox content.

土豪我们做朋友吧 2025-01-24 10:53:57

@color/coloraccent
使用此功能,在Android中是默认的颜色
或者您可以在color.xml中自定义颜色

@color/colorAccent
use this ,it's default color in android
or you can customize your color in the color.xml

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文