gpt4 book ai didi

java - 有没有办法从android :drawable programatically?设置背景

转载 作者:行者123 更新时间:2023-11-29 08:03:17 26 4
gpt4 key购买 nike

我知道这可以用这种方式在 xml 中完成

android:background="@android:drawable/editbox_dropdown_dark_frame"

上面这行是我的想法所以它可能有一些错误,但基本上就是这样。现在我怎样才能以编程方式做同样的事情呢?

谢谢

最佳答案

您可以这样做(从 View 子类):

setBackgroundResource(android.R.drawable.editbox_dropdown_dark_frame);

如果您有对 View 的引用(例如,来自 findViewById),您可以做同样的事情:

View v = . . .;
v.setBackgroundResource(android.R.drawable.editbox_dropdown_dark_frame);

如果愿意,您可以直接检索 Drawable 本身:

Drawable d = getResources().getDrawable(
android.R.drawable.editbox_dropdown_dark_frame);

关于java - 有没有办法从android :drawable programatically?设置背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13078324/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com