how to change resource color to int color in android

how to change resource color to int color in android

To change a resource color to an int color in Android, you can use the getColor method of the Resources class.

Here's an example of how you might do this in an activity:

import android.content.res.Resources;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Resources resources = getResources();
        int color = resources.getColor(R.color.my_color);

        // Use the color
        // ...
    }
}
Sourc‮ual.www:e‬tturi.com

In this example, the getColor method is used to get the color value of the resource with the ID R.color.my_color. The color value is returned as an int, which can be used as desired.

Created Time:2017-11-01 12:05:13  Author:lautturi