- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试在 TextView 上设置 Roboto Light 字体。我从 here 下载了 Roboto 字体.
我从我的代码中所做的就是:
sRobotoItalic = Typeface
.createFromAsset(getContext().getAssets(), "fonts/Roboto_v1.2/Roboto-Italic.ttf");
final TextView textView = (TextView) view.findViewById(R.id.text_view);
textView.setTypeface(sRobotoItalic);
我的 TextView 的高度几乎是实际文本高度的 5 倍。
我确信这是我的 TextView 而不是其他 View 来改变它的大小(已经玩过背景颜色)并且是那个特定的字体导致了这个问题(我试图在我的 TextView 上设置不同的字体,但没有任何错误当我使用它们时)。
现在,我找到了解决这个问题的方法
sRobotoItalic = Typeface
.createFromAsset(getContext().getAssets(), "fonts/Roboto_v1.2/Roboto-Italic.ttf");
final TextView textView = (TextView) view.findViewById(R.id.text_view);
textView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
int height = v.getHeight();
mTypefaceUtils.setRobotoItalicTypeFace(passedExamsLabel);
((TextView) v).setHeight(height);
}
});
但这与其说是一种解决方案,不如说是一种技巧。如果同一问题有更多 TextView ,代码很快就会变得困惑。
这是 TextView xml(第二个)
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/marginBottom"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginTop="@dimen/marginTop"
android:padding="4dp">
<TextView
android:id="@+id/text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerInParent="true"
android:layout_marginLeft="5dp"
android:textStyle="italic"
android:textSize="@dimen/text_size" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:text="0"
android:textSize="@dimen/text_size"
android:textStyle="italic" />
</RelativeLayout>
我做错了什么吗?我该如何修复?
最佳答案
好的,伙计们,不要使用谷歌提供的字体,而是那些:https://github.com/android/platform_frameworks_base/tree/master/data/fonts
我从手机(N5、5.0)中提取字体,效果很好。
关于android - 当我使用 Roboto-Italic.ttf 字体时,为什么 TextView.setTypeface() 夸大地增加了我的 TextView 高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22271897/
我又遇到了另一个问题,这次更令人困惑: public class MainActivity extends Activity { TextView cityData; TextView
出于某种原因,我无法在 SearchView 上设置字体。 这是我尝试更改字体的代码: searchView = findViewById(R.id.searchview_invite_friends
是否可以同时为所有 View (包括 ListView )设置字体,而不是为每个 View 都这样做。谢谢 最佳答案 您可以使用以下方法为布局设置字体 public void setFont(View
Paint.setTypeface 不适用于斜体,或者我做错了事。我可以创建普通、粗体、等宽和衬线文本,但无法创建斜体文本。它总是看起来很正常(或者在粗斜体的情况下,它看起来很粗)。 //Th
我在运行时设置字体。但它没有反射(reflect)在我的应用程序中。 package com.example.practice; import android.os.Bundle; import an
我有一个带有 OnItemClickListener 的 ListView,我在其中设置背景以指示该行已被选中 itemList.setOnItemClickListener(new OnItemCl
我有一些小问题,我已经执行了很多次并且也正确执行了。我想使用我的自己的字体,resp。外部 google Roboto 字体用于我在 MainActivity 中的按钮文本,所以我使用了一个简单的代码
我在应用程序中使用自定义 View 组件,通过 Paint/Canvas 在屏幕上绘制一些文本。 我正在使用以下代码(在我调用 canvas.drawText() 之前)将我的文本设为斜体: mPai
我想从 url 设置TypeFace,例如:https://github.com/anak10thn/frontend-homepage/raw/master/font/helvetica-regul
本文整理了Java中com.github.mikephil.charting.components.YAxis.setTypeface()方法的一些代码示例,展示了YAxis.setTypeface(
当我运行我的应用程序时,它卡住了,所以我检查了 Loccat,它似乎带有样式的 setTypeface : 0 错误循环。 最佳答案 这来自对的调用 view.setTypeface(Typeface
我正在尝试在 TextView 上设置 Roboto Light 字体。我从 here 下载了 Roboto 字体. 我从我的代码中所做的就是: sRobotoItalic = Typeface
我是一名优秀的程序员,十分优秀!