V8.1中button的Toggle如何改变切换后默认的红色?

lv_obj_add_flag(btn1, LV_OBJ_FLAG_CHECKABLE);
这段代码点击按钮时会使button由蓝色切换到红色状态,那如何更改这个默认的红色呢?

Here is the solution about your question.
I am Korean and I cannot speak Chinese, so please use Google Translate.

以下是您提出的問題的解決方案。
我不會說中文,所以請使用谷歌翻譯。

Here is the answer,

이건 기본 상식에 대한 문제라고 생각합니다.
질문을 할 자격이 없는 사람이 물어보면 누가 답을 해줄까요?
제 생각에는 이 포럼에 있는 대부분의 사람들은 영어가 엄마의 언어가 아닙니다. 그럼에도 불구하고 최소한 구글 번역기라도 써서 질문 하는게 예의 아닌가요? 중국사람에게 질문하실꺼면 중국 LVGL포럼에 질문을 올리시고, 중국 LVGL포럼이 없으면 혼자 해결 하세요!
아시아계 전체가 당신때문에 평가절하 받습니다.

이것때문에 구글 번역기 쓰신 다른 사용자에게 죄송합니다.
그러나 제 생각에는 질문 작성자가 다른 언어에 대해 우리가 어떤 수고를 해야되는지 경험해야 된다고 생각합니다.

Sorry about the foreign languges, but I think he need to know what he is doing.

谁给你的资格在这里装逼,你想看我的问题就给我老老实实翻译!!!这个就是入门级的版块,我在这里提问有什么问题吗?对于一个lvgl新手来说,基本的常识我一定都会吗?不会不可以来提问吗?少来道德绑架。不会解决我的问题就闭嘴,没人说你是哑巴。sb…

1 Like

Dear @jr_ol,
Isn’t that a common sense to make a question which can be understood by whom read that.
Not like you did that. even “Get started” section or not.
How can you understand the Korean?
Do you really want to someone who intends to answer your question, do same thing?

I am also a super newbie at this LVGL.
I just don’t understand why you are still writing your language for this. that is all.
Is it common sense to you ?

English is not my native language. But here I use english - this makes it possible to get help from the largest number of users.

Please use English (or at least include an English translation of your message) on the LVGL forum. Thanks. :slightly_smiling_face:

噢,亲爱的韩国棒子粒,感谢您在百忙之中使用谷歌翻译来回答我的问题,在新的一
年,请允许我向你以及你的家人致以最诚挚的问候:祝你阖家富贵。但是我感觉你正事不干,屁事到一大堆。所以请你自尊自爱喔。nmsl。

1 Like

好的,非常感谢你的提醒,我会好好学习,天天向上的。

1 Like

lv_obj_add_flag(btn1, LV_OBJ_FLAG_CHECKABLE);
接着用这个函数:void lv_obj_set_style_bg_color(struct _lv_obj_t * obj, lv_color_t value, lv_style_selector_t selector)设置背景色
像这样设置CHECKED状态下的背景色是橘色
lv_obj_set_style_bg_color(btn1, lv_palette_main(LV_PALETTE_ORANGE), LV_STATE_CHECKED);
这类style函数的selector可以用对象的状态(像上面的LV_STATE_CHECKED)来表示,也可以用对象的部分(像LV_PART_MAIN)。在官方例程里面是混着用的我没咋整明白。
另外lv_obj_set_style_bg_color(btn1, lv_palette_main(LV_PALETTE_ORANGE), LV_STATE_CHECKED);这一句可以参考官方文档的button栏第二个例程倒数第九行lv_obj_add_style(btn1, &style_pr, LV_STATE_PRESSED);
国内的lvgl论坛可以去正点原子那看看,不过人很少

1 Like

懂了,原来在设置背景色的时候换成LV_STATE_CHECKED就可以了。非常感谢您 :grinning:

刚刚去看了文档,然后看到了相关说明,之前没有仔细看 :cry:样式 — LVGL 文档

Esto me hace pensar que yo añadiría un punto en las normas del foro, para que todo el mundo utilice el ingles.

1 Like

okok.you happy just ok.sbwy

dear @jr_ol
And one more thing, I am sorry about the reply above.
That is not good thing to do.
Anyway learning is always good thing, Hope you keep up!

在一个外国论坛里用英语提问简直是基本都不能再基本的素养了,就算是没有懂中文的来看,那些懂英文的也会来去看可以帮你解决问题。就这臭脾气,还是老实去贴吧里当伸手党吧,搞啥开发呢这… 笑死人了 @jr_ol

That is the basic politeness to post question written in ENGLISH here, an international forum. Even for those who don’t understand Chinese could also help you with it, but instead you kinda spread your rages in others trying to remind you to try ask questions in English. You are lucky that you’re not in Stack Overflow bro, I don’t even want to waste time answer your question even I know the answer to it.

自以为是的滚一边,别占用我时间。中国不是常任理事国吗?中文不是国际语言是吗?你也知道是国际论坛是吧,什么叫文化多元化?为什么浏览器会有翻译功能?就你死古板还搞开发?你不想看中文就闭嘴,别让我diao你。

教你一句中国话,待我以礼,我还之以礼。就你还教训我,有本事别说中文!sbwy。

不是每个人都像你这样是非不分,善意的提醒我会不听吗?恶言相向我为什么不骂回去,像你这样窝囊吗?自觉低人一等?还有我告诉你,外国论坛就没有中国人吗?我写给来这个论坛的中国人看不行吗?还有我的问题已经解决,等你这个吃饱了撑着的傻嗨看到我的回复我就会把帖子删掉,不让像你这样的疯狗再乱咬人。。。影响不好。

I’m going to lock this post as the original issue is solved and it doesn’t appear that there is much constructive coming out of this discussion (however, I’m using a translator).