java - 更改 WheelView 的 TextView

标签 java android fonts textview

我正在使用Yuri Kanivets' WheelView在我的项目中。

出于翻译目的,我使用自定义字体制作了自定义 TextView。 WheelView 使用 TextView 来显示文本。我想在 Wheelview 中使用自定义 Textview,以便它以自定义字体显示文本。我怎么做?

我不想更改 Wheelview 的原始来源,以防我必须将其用于其他应用程序。

轮视适配器代码:

/**
* Adapter for string based wheel. Highlights the current value.
*/
private class DateArrayAdapter extends ArrayWheelAdapter<String> {
   // Index of current item
   int currentItem;
   // Index of item to be highlighted
   int currentValue;

   /**
    * Constructor
    */
   public DateArrayAdapter(Context context, String[] items, int current) {
       super(context, items);
       this.currentValue = current;
       setTextSize(16);
   }

   @Override
   protected void configureTextView(TextView view) {
       super.configureTextView(view);
       if (currentItem == currentValue) {
           view.setTextColor(getResources().getColor(R.color.holo_blue));
       }
       view.setTypeface(Typeface.SANS_SERIF);
       view.setTextSize(18);
   }

   @Override
   public View getItem(int index, View cachedView, ViewGroup parent) {
       currentItem = index;
       return super.getItem(index, cachedView, parent);
   }
}

最佳答案

使用您自己的 View 创建布局 xml。假设它是 layout_item.xml。使用 android:id="@+id/text" 将 View (自定义 TextView )的 id 设置为文本

在您的适配器上使用它:

adapter.setItemResource(R.layout.layout_item);
adapter.setItemTextResource(R.id.text);

我想现在应该可以了

关于java - 更改 WheelView 的 TextView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14690393/

相关文章:

java - 窗口调整大小事件?

java - 如何动态地将 android xml 布局作为参数传递给自定义数组适配器类

java - Android中如何获取ArrayList的模型数据类型?

css - @font-face 不工作,字体似乎没有加载

html - HTML 中的非标准字体是个坏主意吗?

java - 尝试在 Java 中更新 MySQL 数据库时数组索引越界异常

java - 先后在Android中运行Handler Task

java - 如何在 Java 中将示例 JSON 转换为 JSON 模式

android - 检查 fragment 是否在 framelayout 中显示或不在 android 中?

utf-8 - 在 gnuplot 中使用自定义 unicode 字体生成 (e)ps 或 pdf 的斜体和粗体拉丁文和希腊字母