1
我想制作自定义字体文本视图。自定义字体不能在片段中工作Android Studio
我得在FragEarnCredits.java:
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (aiView == null) {
aiView = inflater.inflate(R.layout.fragment_earn_credits, container, false);
}
t = (TextView) aiView.findViewById(R.id.logo);
Typeface myCustomFont=Typeface.createFromAsset(aiContext.getAssets(),"fonts/bebas.otf");
t.setTypeface(myCustomFont);
在fragment_earn_credits.xml:
<TextView
android:id="@+id/logo"
android:text="Fashion Wallet"
android:gravity="center"
android:textSize="40dp"
android:textColor="@color/md_brown_700"
android:layout_marginTop="100dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
/>
而且我得到空的错误。为什么?请帮助我们!
#EDIT
我试图改变:
Typeface myCustomFont=Typeface.createFromAsset(aiContext.getAssets(),"fonts/bebas.otf");
到
Typeface myCustomFont = Typeface.createFromAsset(getActivity().getAssets(), "fonts/bebas.otf");
0错误,但有没有改变字体。
不工作@aaoo。 0错误,并且字体没有改变 –
@FootballFan,你可以尝试使用另一种字体来查看字体文件是否正常? –
@aaoo它的工作,我正在使用它Photoshop –