gpt4 book ai didi

android - 识别 Assets 文件夹 “Expected expression, but a package name was found”时出错

转载 作者:行者123 更新时间:2023-12-02 13:36:28 24 4
gpt4 key购买 nike

我希望我的应用程序有一个字体,我将.otf放在assets文件夹中,但是在编写代码时assets文件夹无法识别我,我触摸了错误,并且得到了“期望表达但找到了包名” “救命。我在这里留下我的代码

val typeface= TypeFace.createFromAssets(*assets*, "circular_std_black.otf")

class FragmentUno : Fragment(){

override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
// Inflate the layout for this fragment

val typeface = Typeface.createFromAsset(assets, "circular_std_black.otf")
super.onCreate(savedInstanceState)

val view: View = inflater.inflate(R.layout.fragment_music, container, false)
//val btn: Button = view.findViewById(R.id.btnFragment)
//var btn2: Button = view.findViewById(R.id.btnFragm)

return view
}
companion object {
fun newInstance() = FragmentUno()
}
}

最佳答案

您不能只从Fragment调用 Assets ,首先需要调用Activity。

val typeface = Typeface.createFromAsset(activity.assets, "circular_std_black.otf")

关于android - 识别 Assets 文件夹 “Expected expression, but a package name was found”时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55563978/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com