繁体   English   中英

自定义字体在Fragment Android Studio中不起作用

[英]Custom Font not working in Fragment Android Studio

我想制作一个自定义字体textview。

我有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"
  />

而且我得到了无效的错误。 为什么? 请帮帮我们!

#编辑

我试图改变:

 Typeface myCustomFont=Typeface.createFromAsset(aiContext.getAssets(),"fonts/bebas.otf");

Typeface myCustomFont = Typeface.createFromAsset(getActivity().getAssets(), "fonts/bebas.otf");

和0错误但没有改变字体。

Typeface font = Typeface.createFromAsset(getActivity().getAssets(), "fonts/customfont.ttf");

您要在片段类中发送的上下文,您必须使用您的实际上下文。

希望能帮助到你! 干杯!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM