0

我有一个搜索引擎,可以在预定义的字符串中执行搜索。我想以自定义字体而不是 android 默认显示结果列表!我还有一个简单的自定义字体应用程序。但不能为此做一个好的适配器。

这是自定义字体应用程序

 /** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    TextView tv = (TextView)findViewById(R.id.tv);
    Typeface cFont = Typeface.createFromAsset(getAssets(), "fonts/jcc.ttf");
    tv.setTypeface(cFont);




<TextView  
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text="@string/hello"
android:textSize="18sp"
android:id="@+id/tv"
/>

这是产品搜索应用程序:

公共类 ProductList 扩展 Activity {

   // List view
private ListView lv;

// Listview Adapter
ArrayAdapter<String> adapter;

// Search EditText
EditText inputSearch;

// ArrayList for Listview
ArrayList<HashMap<String, String>> productList;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_product_list);

    String asim02 = System.getProperty("line.separator");

    String products[] = {
            "Apple" + asim02 +"Definition1", 
            "Orange" + asim02 +"Definition2",
            "Banana"+ asim02 +"Definition3", 
            "Onion"+ asim02 +"Definition4", };


    lv = (ListView) findViewById(R.id.list_view);


    // Adding items to listview
    adapter = new ArrayAdapter<String>(this, R.layout.list_item, R.id.p_list,   products);
    lv.setAdapter(adapter);




<TextView

        android:textColor="?android:textColorPrimary"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="15sp"
        android:id="@+id/p_list"
        />

请帮忙制作适配器!!!我很新,看不懂!!!需要你的帮助。

4

2 回答 2

0

您必须按照 Pravin 的建议使用自定义适配器。在 getview() 方法中,您必须为 texview 设置字体。您必须将 TrueType (TTF) 甚至 OpenType 文件 (OTF) 字体放入项目中的 assets 文件夹中。

    TextView tv = (TextView) findViewById(R.id.myfontfile);
    Typeface face = Typeface.createFromAsset(getAssets(),"fonts/CHOCD.otf");
    tv.setTypeface(face);

您可以在以下链接中查看更多详细信息http://vimaltuts.com/android-tutorial-for-beginners/android-custom-font-example

于 2012-12-02T03:46:38.337 回答
0

为此,您必须使用自定义 ListView 适配器并在其 getView 方法中设置字体。

一些教程: 教程 1 更多 Tuts

于 2012-12-01T18:07:24.360 回答