java - android微调器更改字体字体

标签 java android

我将在我的微调器中将文本字体更改为 arialbold 我将如何操作。下面是我的代码:-

ArrayAdapter<CharSequence> genderAdap = ArrayAdapter.createFromResource(getActivity(), R.array.gender,R.layout.spinner_item);


genderAdap.setDropDownViewResource(R.layout.spinner_item);

ddlGender.setAdapter(genderAdap);

最佳答案

Class :

public class testActivity extends Activity {

    private static final String[] COUNTRIES = new String[] { "Belgium",
            "France", "Italy", "Germany", "Spain" };
    private Spinner mySpinner;
    private Typeface myFont;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.newlay);

        mySpinner = (Spinner) findViewById(R.id.spinner1);
        myFont = Typeface.createFromAsset(getAssets(), "gujarti.ttf");
        MyArrayAdapter ma = new MyArrayAdapter(this);
        mySpinner.setAdapter(ma);
    }

    private class MyArrayAdapter extends BaseAdapter {

        private LayoutInflater mInflater;

        public MyArrayAdapter(testActivity con) {
            // TODO Auto-generated constructor stub
            mInflater = LayoutInflater.from(con);
        }

        @Override
        public int getCount() {
            // TODO Auto-generated method stub
            return COUNTRIES.length;
        }

        @Override
        public Object getItem(int position) {
            // TODO Auto-generated method stub
            return position;
        }

        @Override
        public long getItemId(int position) {
            // TODO Auto-generated method stub
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            // TODO Auto-generated method stub
            final ListContent holder;
            View v = convertView;
            if (v == null) {
                v = mInflater.inflate(R.layout.my_spinner_style, null);
                holder = new ListContent();

                holder.name = (TextView) v.findViewById(R.id.textView1);

                v.setTag(holder);
            } else {

                holder = (ListContent) v.getTag();
            }

            holder.name.setTypeface(myFont);
            holder.name.setText("" + COUNTRIES[position]);

            return v;
        }

    }

    static class ListContent {

        TextView name;

    }
}

Layout :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
   android:layout_width="fill_parent"  
   android:layout_height="fill_parent"  
   android:orientation="vertical" >  
   <Spinner  
     android:id="@+id/spinner1"  
     android:layout_width="match_parent"  
     android:layout_height="wrap_content" />  
 </LinearLayout> 

my_spinner_style.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
   android:layout_width="fill_parent"  
   android:layout_height="fill_parent" >  
   <TextView  
     android:id="@+id/textView1"  
     android:layout_width="match_parent"  
     android:layout_height="wrap_content"  
     android:text="Large Text"  
     android:textAppearance="?android:attr/textAppearanceLarge" />  
 </LinearLayout> 

TTF FILES

关于java - android微调器更改字体字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19150588/

相关文章:

java - 如何只标记一个 Sentry 事件?

java - Android JNI : SIGSEGV on CallObjectMethod

android - 在 Android 中支持使用 OpenType 字体的复杂文本布局

android - 带有 Android Gradle 的 Jenkins 无法解析 com.android.tools.build :gradle:1. 3.1

android - 当我更改手机语言设置时,Platform.device.language 返回错误的语言

android - 在 Android 上将 Google 日历与我自己的日历应用程序同步

java - 使用@RequestLine时设置媒体类型

java 数据输出流 getOutputStream() getInputStream()

java - 如何使用mstor?

Android:使用 "progress"GUI 在后台线程中从 Web 加载数据?