当前位置: 代码迷 >> Android >> android-对资源的运用
  详细解决方案

android-对资源的运用

热度:25   发布时间:2016-05-01 16:55:54.0
android-对资源的使用

1、java

1)字符串

String mystr=activity.getString(R.string.test_string);

textView.setText(simpleString);

2)尺寸

float dimen=activity.getResouces().getDimension(R.dimen.mysize_in_pixels);

3)图像资源

BitmapDrawable d=acitivity.getResouces().getDrawable(R.drawable.sample_image);

4)色图资源

ColorDrawble?redDrawable=(ColorDrawble)?activity.getResources().getDrawable(R.drawable.redrectangle);

?

?

2、xml

1)字符串

<TextView android:layout_width="fill_parent"

?????????????????android:layout_height="wrap_content"

???????????????? android:textAlign="center"

?????????????????android:text="@string/tagged_string"/>

2)尺寸

<TextView android:layout_width="fill_parent"

?????????????????android:layout_height="wrap_content"

???????????????? android:textSize="@dimen/mediu_szie"/>?

?

3)图像资源

?

adroid:background="@drawable/sample_image"??

4)色图资源

android:background="@drawable/red_rectangle"

?

  相关解决方案