该Resources.getColor(int id)方法已被弃用.
@ColorInt
@Deprecated
public int getColor(@ColorRes int id) throws NotFoundException {
return getColor(id, null);
}
Run Code Online (Sandbox Code Playgroud)
我该怎么办?
android android-resources android-mnc android-6.0-marshmallow
在XML中,我们可以通过textColor属性设置文本颜色,例如android:textColor="#FF0000".但是如何通过编码来改变它呢?
我尝试过类似的东西:
holder.text.setTextColor(R.color.Red);
Run Code Online (Sandbox Code Playgroud)
哪里holder只是一个类,text是类型TextView.红色是以字符串形式设置的RGB值(#FF0000).
但它显示的是不同的颜色而不是红色.我们可以在setTextColor()中传递什么样的参数?它说int,在文档中,它是资源参考值还是其他任何东西?
我正在尝试设置视图的背景颜色(在本例中为Button).
我用这个代码:
// set the background to green
v.setBackgroundColor(0x0000FF00 );
v.invalidate();
Run Code Online (Sandbox Code Playgroud)
它会导致Button从屏幕上消失.我做错了什么,以及在任何视图上更改背景颜色的正确方法是什么?
谢谢.
保持字体和颜色样式的最佳做法是什么.我做了我所用,以改变如按钮单独的元素颜色的colors.xml文件,但我不知道怎么的Android开发人员想组织自己的风格.
例如,我希望所有屏幕都具有相同的背景颜色.我怎么做?这是我需要为每个Activity布局xml指定的东西吗?或其他地方?我该如何完成它?
我需要添加什么,以便我有一个背景图像和main.xml的背景颜色
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="330dp"
android:layout_height="600dp"
android:layout_gravity="center|center_vertical"
android:background="@drawable/background"
>
Run Code Online (Sandbox Code Playgroud) 如何将整个背景页设为白色?我有一个listview并试图在xml中设置backgroundcolor白色,但它没有用.这些是我的xmls:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ListView
android:id="@+id/list" android:layout_width="fill_parent"
android:clickable="true" android:layout_height="fill_parent"></ListView>
Run Code Online (Sandbox Code Playgroud)
唯一真正变白的是:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/naam" android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:textSize="16sp" >
</TextView>
Run Code Online (Sandbox Code Playgroud)
这是我的java代码:
public class Contactenlijst extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final HashMap<Integer, Personeel> personeelmap = new HashMap<Integer, Personeel>();
ArrayList<String> list = new ArrayList<String>();
// Get the data (see above)
JSONObject json = Database
.getJSONfromURL("http://fabian.nostradamus.nu/Android/getcontactinfo.php");
try {
JSONArray contactinfo = json.getJSONArray("contactlijst");
// Loop the Array
for (int i = 0; i < …Run Code Online (Sandbox Code Playgroud) android ×6
colors ×2
android-mnc ×1
background ×1
listview ×1
set ×1
textview ×1
view ×1
xml ×1