我希望我的应用程序有一个字样,我将.otf放在资产文件夹中,但是在编写代码时,资产文件夹无法识别我,我触摸了错误,并且得到了“期望的表达式但找到包名称”帮助。我在这里留下我的代码
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()
}
}
答案 0 :(得分:1)
您不能只从片段调用资产,首先需要调用活动。
val typeface = Typeface.createFromAsset(activity.assets, "circular_std_black.otf")