当前位置: 首页 > 面试题库 >

Android Spinner更改字体字体

令狐高洁
2023-03-14
问题内容

我打算在微调器中将文本字体更改为arialbold。以下是我的代码:-

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


genderAdap.setDropDownViewResource(R.layout.spinner_item);

ddlGender.setAdapter(genderAdap);

问题答案:

类:

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;

    }
}

版面:

<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文件



 类似资料:
  • 本文向大家介绍iOS更改字体,包括了iOS更改字体的使用技巧和注意事项,需要的朋友参考一下 示例 Swift Objective-C            

  • 使用DOM PDF创建一些报告,但是我唯一遇到的问题是设置无衬线字体。 我尝试了几乎所有的方法来设置CSS中可能的字体,但它总是以衬线字体呈现。 我并没有试图呈现一个自定义字体,只是一些简单的东西,比如helvetica或arial。 有没有其他人有过这个问题,或者知道为什么它可能会默认为衬线? 注意:应用程序在CodeIgnitor上运行。

  • 除了这个问题:更改超文本标记语言电子邮件正文字体类型和大小在VBA,我想知道如何才能改变字体大小 当我从代码中删除字体大小时,它确实改变了字体系列。 谢谢你的协助,

  • 问题内容: 有人可以建议一种方法来更改动态创建的AlertDialog中的字体(标题和正文)吗?我尝试了很多方法,但是没有一个起作用。代码是: 问题答案: 您应该设置布局的自定义视图,而不是设置alertdialog的文本。在执行此操作之前,请修改视图的字体。 并设置警报对话框的视图,请致电, 尽管据我所知,这不会更改您的标题。 更新 我看到您无法理解我的意思,所以这是一个完整的示例 这使用的是我

  • 我用Word编译了这段代码,它突然出现: 编译错误:应为:表达式 当我改变时就会发生这种情况 代码如下:

  • 我正在编写一个应用程序,它使用PDFbox库来填充PDF文件中的字段。 在其中一个字段中,我将文本设置为希伯来字母。 当我在Android设备上运行代码时,我会得到以下日志: 我试图在堆栈溢出中找到一些关于它的信息,但我找到的答案都与填充表单有关。它都与有关。 你能帮我解决这个错误并用PDFBox在表格中填写希伯来字母吗?