Reputation: 29
I have a spinner to choose between some custom fonts. so I tried following codes to set this spinner. But there is an error says (cannot resolve symbol creatFromAsset). I don't know where I made a mistake!
try {
font.setAdapter(new ArrayAdapter<>(this,android.R.layout.simple_spinner_item, fonts));
} catch (Exception ex){
Toast.makeText(MainActivity.this,"setAdapters Error", Toast.LENGTH_SHORT).show();
}
font.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
switch(position) {
case 0:
Typeface typeface = new Typeface.createFromAsset(getAssets(),"assets/Xanadu.ttf");
edt2.setTypeface(typeface);
}
}
});
Upvotes: 2
Views: 125
Reputation: 11096
getAssets
itself points to the folder of assets and you have no need to repeat assets again in file address:
Typeface typeface = Typeface.createFromAsset(getAssets(),"Xanadu.ttf");
Upvotes: 1
Reputation: 8254
TypeFace
constructor is not public, so you can't use new
.
Do instead:
Typeface typeface = Typeface.createFromAsset(getAssets(),"Xanadu.ttf");
Upvotes: 2