我希望我的应用程序有一个字体,我把我的.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()
}
}
您不能只从片段调用资产,首先需要调用活动。
val typeface = Typeface.createFromAsset(activity.assets, "circular_std_black.otf")