簡體   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