相关疑难解决方法(0)

在Android 6.0 Marshmallow(API 23)上弃用了getColor(int id)

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

686
推荐指数
12
解决办法
27万
查看次数

如何在代码中设置TextView的文本颜色?

在XML中,我们可以通过textColor属性设置文本颜色,例如android:textColor="#FF0000".但是如何通过编码来改变它呢?

我尝试过类似的东西:

holder.text.setTextColor(R.color.Red);
Run Code Online (Sandbox Code Playgroud)

哪里holder只是一个类,text是类型TextView.红色是以字符串形式设置的RGB值(#FF0000).

但它显示的是不同的颜色而不是红色.我们可以在setTextColor()中传递什么样的参数?它说int,在文档中,它是资源参考值还是其他任何东西?

android colors textview

520
推荐指数
15
解决办法
96万
查看次数

如何设置视图的背景颜色

我正在尝试设置视图的背景颜色(在本例中为Button).

我用这个代码:

// set the background to green
v.setBackgroundColor(0x0000FF00 );
v.invalidate();
Run Code Online (Sandbox Code Playgroud)

它会导致Button从屏幕上消失.我做错了什么,以及在任何视图上更改背景颜色的正确方法是什么?

谢谢.

android background view colors set

171
推荐指数
13
解决办法
41万
查看次数

Android - 如何设置所有屏幕的背景颜色?

保持字体和颜色样式的最佳做法是什么.我做了我所用,以改变如按钮单独的元素颜色的colors.xml文件,但我不知道怎么的Android开发人员想组织自己的风格.

例如,我希望所有屏幕都具有相同的背景颜色.我怎么做?这是我需要为每个Activity布局xml指定的东西吗?或其他地方?我该如何完成它?

android android-layout

72
推荐指数
3
解决办法
8万
查看次数

Android布局背景图像和颜色

我需要添加什么,以便我有一个背景图像和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)

android android-layout

9
推荐指数
1
解决办法
3万
查看次数

在listview中设置背景颜色

如何将整个背景页设为白色?我有一个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)

xml android listview background-color

4
推荐指数
2
解决办法
4万
查看次数