yes, in andriod application we have nice project structure to organize the project with the help of
speration/extranalization as resources in the project in res folder.
based on resource type :
strings,
images,color, menu,styles ..has their respective folders like Values,Drawable,Colors,Menu...are predefined structures should maintain. buf finally we called all of them as resources.
as well extranalizating resoures and alternative resources are supports specific
device configurations,
different languages,
based screen sizes...ect.
ColorStateList is a list resouce :
clolorstatelist is an object we can define as an
mycolor.xml that can apply a color to a viewobject, so that depending on the
state/behaviour of the view object the color gets changed on the view componet.
we can apply color to the view component in 2 ways
1. design time 2.runtime
any of the above we need to create an xml which is type Color List.
select Android Project(ColorsProject)--New --Other--New android
xml file----
Type of Resouce : color List
File : mycolors
Root Element : selector
then as
mycolors.xml is created with selector as root element. now we added two colors with two behaviours(pressed,checked).
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true" android:color="#
0f0"/>
<item
android:state_checked="true" android:color="#
00f" />
<item android:color="#
f00"/>
</selector>
at design time:
<Button
android:id="@+id/button1"
android:textColor="@
color/mycolors"></Button>
at runtime/programatic time:
public class MainActivity extends Activity implements
OnClickListener {
Button b2,b3;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b2=(Button)findViewById(R.id.
button2);
b2.setOnClickListener(
this);
b3=(Button)findViewById(R.id.
button3);
b3.setOnClickListener(
this);
}
@Override
public void onClick(View v)
{
if(v==b2)
b2.setTextColor(getResources().getColor(R.color.mycolors));
else
b3.setTextColor(getResources().getColorStateList(R.color.mycolors));
}
we have 2 more options based on class, and configuration also. for apply resouce to view object.