在我的應用程序,我有一個微調,顯示星期日,星期一,星期二,星期四,星期五,星期六。我想顯示每個項目在不同的字體style.ie週日在泰晤士報新羅馬字體,星期二在Calibri字體,星期三在Arialic Hollow字體就像那樣。我在資產中創建的字體文件夾中採用這些字體。請幫助我如何去做。如何將不同的字體樣式應用於微調器中的不同項目?
我的主要活動是
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
public class AndroidCustomSpinner extends Activity{
String[] DayOfWeek = {"Sunday", "Monday", "Tuesday",
"Wednesday", "Thursday", "Friday", "Saturday"};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Spinner mySpinner = (Spinner)findViewById(R.id.spinner);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
R.layout.row, R.id.weekofday, DayOfWeek);
mySpinner.setAdapter(adapter);
}
}
我row.xml是
<?xml version="1.0" encoding="utf-8" ?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/weekofday"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
和我的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="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Spinner" />
<Spinner
android:id="@+id/spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
寫的customAdapter和getView迭代和getDropDownView方法改變的TextView的字體根據您的需要.. –
就像一個字體在Microsoft Word中下拉右鍵? – Kedarnath
亞以ms字出現的相同方式 – Lakshmipathi