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 // ... } }Sourcual.www:etturi.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.