Android:在gridview中使用自定义字体

时间:2014-02-24 22:51:43

标签: android gridview fonts

您好我正在尝试使用自定义字体显示ABC字母,但只有在我点击setOnItemClickListener功能后才会显示自定义字体。我可以在gridview字符串上应用自定义字体吗?

public class GridViewAndroidExample extends Activity {
    GridView gridView;
    final String[] numbers = new String[] {
            "A", "B", "C", "D", "E",
            "F", "G", "H", "I", "J",
            "K", "L", "M", "N", "O",
            "P", "Q", "R", "S", "T",
            "U", "V", "W", "X", "Y", "Z"};

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_grid_view);

        gridView = (GridView) findViewById(R.id.gridview1);

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, numbers);

        Typeface tf = Typeface.createFromAsset(getAssets(), "kids.ttf");
        gridView.setTypeface(tf);

        gridView.setAdapter(adapter);


        gridView.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View v,
                int position, long id) {
                Typeface tf = Typeface.createFromAsset(getAssets(), "kids.ttf");
                ((TextView) v).setTypeface(tf,Typeface.BOLD);
                ((TextView) v).setTextColor(Color.RED);
               Toast.makeText(getApplicationContext(), ((TextView) v).getText(), Toast.LENGTH_SHORT).show();
            }
        });
    }
 }

0 个答案:

没有答案