I am trying to set external typeface in one of my expandable list view. I am trying like below
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
String headerTitle = (String) getGroup(groupPosition);
String headerTitleDate = (String) getGroupD(groupPosition);
if (convertView == null) {
LayoutInflater layoutInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = layoutInflater.inflate(R.layout.list_group, null);
}
Typeface bold = Typeface.createFromAsset(getContext().getAssets(), "shruti.ttf");
TextView listTitle = (TextView) convertView
.findViewById(R.id.tv_listtitle);
TextView listTitleDate = (TextView) convertView
.findViewById(R.id.tv_date);
listTitle.setTypeface(null, Typeface.BOLD);
listTitle.setText(headerTitle);
listTitleDate.setTypeface(null, Typeface.BOLD);
listTitleDate.setText(headerTitleDate);
return convertView;
}
But I am getting getAssets() cannot resolved. I have tried to use it with Context and without it but not success. Can anyone please suggest me what is wrong with it ?
Thanks
You should use the view's context when doing this, since it is inside an adapter.
You can get the view's context by: view.getContext()
Replacing this line:
Typeface bold = Typeface.createFromAsset(getContext().getAssets(), "shruti.ttf");
with this:
Typeface bold = Typeface.createFromAsset(convertView.getContext().getAssets(), "shruti.ttf");
will fix the error. Hope this helps, let me know if it does.
This is how i do it
STEP 1:
I first make a customizable font class, for your case you are using shruti.ttf
public class Shruti extends TextView{
public Champagne(Context context) {
super(context);
applyCustomFont(context);
}
public Champagne(Context context, AttributeSet attrs) {
super(context, attrs);
applyCustomFont(context);
}
public Champagne(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
applyCustomFont(context);
}
private void applyCustomFont(Context context) {
Typeface customFont = FontCache.getTypeface("shruti.ttf", context);
setTypeface(customFont);
}
}
STEP 2:
Then you also include a FontCache class
public class FontCache {
private static HashMap<String, Typeface> fontCache = new HashMap<>();
public static Typeface getTypeface(String fontname, Context context) {
Typeface typeface = fontCache.get(fontname);
if (typeface == null) {
try {
typeface = Typeface.createFromAsset(context.getAssets(), fontname);
} catch (Exception e) {
return null;
}
fontCache.put(fontname, typeface);
}
return typeface;
}
}
STEP 3:
Then lastly ,you attach the customized class on to your TextView. in your xml item class like this
<company.override.huzykamz.pixsar.customization.Shruti
android:layout_width="match_parent"
android:id="#+id/post_desc"
android:layout_height="wrap_content"
android:text=""
android:textColor="#000"
android:textSize="15dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:paddingBottom="15dp" />
NOTE:
company.override.huzykamz.pixsar.customization is just a package name example , but you just put yours.
Instead of
<TextView
android:layout_width="match_parent"
android:id="#+id/post_desc"
android:layout_height="wrap_content"
android:text=""
android:textColor="#000"
android:textSize="15dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:paddingBottom="15dp" />
Hope it works well. This is a sure deal solution
Related
For setting a font to android app, I use below function:
public static void persianizer(ViewGroup viewGroup) {
int childCount = viewGroup.getChildCount();
for (int i = 0; i < childCount; i++) {
View child = viewGroup.getChildAt(i);
if (child instanceof ViewGroup) {
persianizer((ViewGroup) child);
continue;
}
if (child instanceof TextView) {
((TextView) child).setTypeface(RootApp.typeface);
}
}
}
It gets the root view of a layout and then set type face for every textview child of that layout. but I think it's not a good solution.
What's the best practice for changing the font of whole application?
You can create your own Font TextView class that will extends TextView and send font according to you want, have look:
public class TypefacedTextView extends TextView {
public TypefacedTextView(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray styledAttrs = context.obtainStyledAttributes(attrs, R.styleable.TypefacedButton);
// String fontName = styledAttrs.getString(R.styleable.TypefacedButton_font);
styledAttrs.recycle();
Typeface typeface = Typeface.createFromAsset(context.getAssets(), "fonts/" +getResources().getString(R.string.roboto_light));
setTypeface(typeface);
}
Save Your fonts file in Assets folder and get by call Typeface.createFromAsset().
Here is the TypeFaceTextview in xml:
<com.demo.TypefacedTextView
android:id="#+id/textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
</com.demo.TypefacedTextView >
Happy coding!!
try this
public class CustomTextView extends android.support.v7.widget.AppCompatTextView {
public CustomTextView(Context context, AttributeSet attrs, int defStyle)
{
super(context, attrs, defStyle);
init();
}
public CustomTextView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public CustomTextView(Context context) {
super(context);
init();
}
private void init() {
Typeface tf = Typeface.createFromAsset(getContext().getAssets(),
"Walkway Black.ttf");
setTypeface(tf);
}
}
and then use this CustomText view in Your layout Like :
<app.com.demo.CustomTextView
android:id="#+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="#dimen/_10dp"
android:inputType=""
android:text="#string/name"
android:textColor="#color/colorSkyBlue"
android:textSize="20sp"
android:textStyle="bold" />
I have a ListView that presents a picture and some text on each row. The picture is loaded dynamically at run time using Universal Image Loader. It works, but the problem is that the pictures are not scaled correctly. I want them to be scaled to retain their original aspect ratio, but instead they are stretched to fill the square dimension of their container thereby distorting many of the images.
The listview adapter is this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent">
<ImageView
android:id="#+id/image"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_margin="6dp"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
android:src="#drawable/my_img"/>
<TextView
android:layout_toRightOf="#+id/image"
android:textSize="16sp"
android:id="#+id/coach_name"
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
The image gets loaded from a server at run time. This is the adapter class:
public class CoachAdapter extends ArrayAdapter<String> {
private static Context context;
private ArrayList<String> coach_list;
private DisplayImageOptions doption=null;
private ImageLoadingListener animateFirstListener =null;
public CoachAdapter(Context context, int textViewResourceId, ArrayList<String> coach_list) {
super(context, textViewResourceId, coach_list);
this.context = context;
this.coach_list = coach_list;
doption=new DisplayImageOptions.Builder()
.showImageForEmptyUri(R.drawable.my_img)
.showImageOnFail(R.drawable.my_img)
.showImageOnLoading(R.drawable.my_img)
.cacheInMemory(true)
.cacheOnDisk(true)
.displayer(new RoundedBitmapDisplayer(8))
.imageScaleType(ImageScaleType.EXACTLY)
.postProcessor(new BitmapProcessor() {
#Override
public Bitmap process(Bitmap bmp) {
return Bitmap.createScaledBitmap(bmp, 32, 32, false);
}
})
.build();
animateFirstListener = new AnimateFirstDisplayListener();
}
#Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
return getCustomView(position, convertView, parent);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
return getCustomView(position, convertView, parent);
}
public View getCustomView(int position, View convertView, ViewGroup parent) {
View row = convertView;
final ViewHolder holder;
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = inflater.inflate(R.layout.row_coach, parent, false);
holder = new ViewHolder();
holder.text = (TextView) row.findViewById(R.id.coach_name);
holder.image = (ImageView) row.findViewById(R.id.image);
row.setTag(holder);
} else {
holder = (ViewHolder) row.getTag();
}
String coach_name = coach_list.get(position);
// get the url string from the database
Coach this_coach = myDB.getCoachFromName(coach_name);
String coach_picture_url = this_coach.getCoachPictureURL();
holder.text.setText(coach_name);
holder.image.setScaleType(ImageView.ScaleType.FIT_CENTER);
ImageLoader imageLoader = ImageLoader.getInstance();
imageLoader.init(ImageLoaderConfiguration.createDefault(context));
imageLoader.displayImage(url, holder.image, doption, animateFirstListener);
return row;
}
private static class AnimateFirstDisplayListener extends SimpleImageLoadingListener {
static final List<String> displayedImages = Collections.synchronizedList(new LinkedList<String>());
#Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
if (loadedImage != null) {
ImageView imageView = (ImageView) view;
boolean firstDisplay = !displayedImages.contains(imageUri);
if (firstDisplay) {
FadeInBitmapDisplayer.animate(imageView, 500);
displayedImages.add(imageUri);
}
}
}
}
private class ViewHolder {
public TextView text;
public ImageView image;
}
}
As I read the UniversalImageLoader docs, this is supposed scale the images based on what is specified in the XML file. I've tried fitCenter and fitXY. No matter what I specify, the image is always square. I've also verified that the dimensions of many of the original images are NOT square, so I know that the scaling distortion is happening here.
Any one see what I am doing wrong? Thank you!
I have a simple GridView with custom Adapter in my layouts. My code is as follows:
CircleActivity.java:
public class CircleActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_circle);
List<Integer> listColors = new ArrayList<>();
listColors.add(getResources().getColor(R.color.colorAccent));
listColors.add(getResources().getColor(R.color.colorPrimary));
listColors.add(getResources().getColor(R.color.colorPrimaryDark));
GridView gridView = (GridView) findViewById(R.id.grid_colors);
CircleAdapter adapter = new CircleAdapter(this,listColors);
gridView.setAdapter(adapter);
}
}
activity_circle.xml:
<?xml version="1.0" encoding="utf-8"?>
<GridView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/grid_colors"
android:layout_width="match_parent"
android:layout_height="match_parent" />
CircleAdapter.java:
public class CircleAdapter extends BaseAdapter{
private Context context;
private List<Integer> listColor;
public CircleAdapter(Context context, List<Integer> listColor) {
this.listColor = listColor;
this.context = context;
}
#Override
public int getCount() {
return listColor.size();
}
#Override
public Integer getItem(int position) {
return listColor.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if(convertView==null){
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.row_grid,parent,false);
holder = new ViewHolder(convertView);
convertView.setTag(holder);
}
else{
holder = (ViewHolder) convertView.getTag();
}
holder.customCircleView.setFillColor(listColor.get(position));
holder.customCircleView.setCircleRadius(100);
return convertView;
}
static class ViewHolder{
private CustomCircleView customCircleView;
public ViewHolder(View row){
customCircleView = (CustomCircleView) row.findViewById(R.id.custom_circle_view);
}
}
}
row_grid.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:background="#color/colorAccent"
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="match_parent">
<com.droidexperiments.gridexpand.CustomCircleView
android:id="#+id/custom_circle_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
custom:fill_color="#color/colorPrimary"
custom:circle_radius="50"
android:padding="25dp" />
</LinearLayout>
CircleView.java:
public class CustomCircleView extends View {
private int circleRadius = 20;
private int fillColor = Color.BLACK;
public CustomCircleView(Context context) {
super(context);
}
public CustomCircleView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
public CustomCircleView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs);
}
#TargetApi(Build.VERSION_CODES.LOLLIPOP)
public CustomCircleView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init(context, attrs);
}
private void init(Context context, AttributeSet attrs) {
TypedArray typedArray = context.obtainStyledAttributes(R.styleable.CustomCircle);
circleRadius = typedArray.getInteger(R.styleable.CustomCircle_circle_radius,20);
fillColor = typedArray.getColor(R.styleable.CustomCircle_fill_color, Color.BLACK);
typedArray.recycle();
}
public int getCircleRadius() {
return circleRadius;
}
public void setCircleRadius(int circleRadius) {
this.circleRadius = circleRadius;
}
public int getFillColor() {
return fillColor;
}
public void setFillColor(int fillColor) {
this.fillColor = fillColor;
}
#Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint paint = new Paint();
paint.setColor(fillColor);
paint.setStyle(Paint.Style.FILL);
canvas.drawCircle(canvas.getWidth()/2,canvas.getHeight()/2,circleRadius,paint);
}
}
attrts.xml:
<declare-styleable name="CustomCircle">
<attr name="fill_color" format="reference|color"/>
<attr name="circle_radius" format="integer"/>
</declare-styleable>
The issue is that screen remains blank and no row is inflated/showing in GridView.
I have checked everything. There is not any issue in GridView or the layout of grid row or in CustomCircleView. If I change adapter to simple ArrayAdapter, it works fine. So, there must be issue with my adapter:
I double checked getView() in adapter;
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if(convertView==null){
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.row_grid,parent,false);
holder = new ViewHolder(convertView);
convertView.setTag(holder);
}
else{
holder = (ViewHolder) convertView.getTag();
}
holder.customCircleView.setFillColor(listColor.get(position));
holder.customCircleView.setCircleRadius(100);
return convertView;
}
but couldn't identify why it shows blank. can anyone help me please?
When you implement a custom view, it is essential that you implement onMeasure. This method will tell the Android framework what size your view should be. Since you didn't specify this for CustomCircleView and used wrap_content in your layout, it had size zero. Therefore, all the elements of the GridView were invisible, making it look like the adapter was not working. I made a simple example implementation of onMeasure that solves your problem (just add this method in CustomCircleView):
#Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int size = View.MeasureSpec.makeMeasureSpec(2 * this.circleRadius, MeasureSpec.EXACTLY);
setMeasuredDimension(size, size);
}
The documentation advises that size stays within the given parameters (widthMeasureSpec and heightMeasureSpec). I have not included that restriction here, you can determine yourself what you want to do in that case.
You can find more information about this in the guide on creating custom components. Specific information about onMeasure can be found here.
I'm aware of a few ways to populate an Android ListView object with a title and a icon but I feel stuck when trying to simplify and improve my code.
This is the scenario:
1 - Creating two arrays
2 - Creating a RowItem class
public class IconRow {
private String title;
private int icon;
public IconRow(String title, int icon) {
this.title = title;
this.icon = icon;
}
public String getTitle() {
return title;
}
public int getIcon() {
return icon;
}
}
3 - Creating a ListAdapter
public class ListAdapter extends BaseAdapter {
Context context;
List<IconRow> rowItem;
String description;
long option;
public ListAdapter(Context context, List<IconRow> rowItem, String description, long option)
{
this.context = context;
this.rowItem = rowItem;
this.description = description;
this.option = option;
}
#Override
public int getCount() {
return rowItem.size();
}
#Override
public Object getItem(int position) {
return rowItem.get(position);
}
#Override
public long getItemId(int position) {
return rowItem.indexOf(getItem(position));
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater mInflater = (LayoutInflater) context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
convertView = mInflater.inflate(R.layout.lv_arrow, null);
ImageView imgIcon = (ImageView) convertView.findViewById(R.id.imageView1);
TextView txtTitle = (TextView) convertView.findViewById(R.id.textView1);
IconRow row_pos = rowItem.get(position);
// setting the image resource and title
imgIcon.setImageResource(row_pos.getIcon());
txtTitle.setText(row_pos.getTitle());
}
return convertView;
}
4 - Creating a Row Layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:background="#android:color/white" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="20dp"
android:layout_marginRight="10dp"
android:fontFamily="sans-serif-light"
android:text="TextView"
android:textColor="#android:color/black"
android:textSize="24dp" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_gravity="right|center"
android:layout_marginLeft="20dp"
android:scaleType="fitEnd"
android:src="#drawable/ic_go"
android:layout_marginRight="0dp" />
</LinearLayout>
5 - Creating the List inside Fragment
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_parameters_settings, container, false);
lv_settings_1 = (ListView) rootView.findViewById(R.id.lv_settings_1);
menutitles = getResources().getStringArray(R.array.array_lv_settings_1);
menuIcons = getResources().obtainTypedArray(R.array.arrow_icons);
menu_iconRow = new ArrayList<>();
for (int i = 0; i < menutitles.length; i++) {
IconRow items = new IconRow(menutitles[i], menuIcons.getResourceId(
i, -1));
menu_iconRow.add(items);
}
adapter_settings_1 = new ListAdapter(getActivity(), menu_iconRow, "No Description", 0);
lv_settings_1.setAdapter(adapter_settings_1);
return rootView;
}
Am I doing it the wrong way? Is there anyway I can simplify this code?
I usually use your way for manage ListView. Probably you know this but give a look at this page http://developer.android.com/training/improving-layouts/smooth-scrolling.html
Your code might call findViewById() frequently during the scrolling of ListView, which can slow down performance. Even when the Adapter returns an inflated view for recycling, you still need to look up the elements and update them. A way around repeated use of findViewById() is to use the "view holder" design pattern.
static class ViewHolder {
TextView text;
TextView timestamp;
ImageView icon;
ProgressBar progress;
int position;
}
I spent all day searching for an answer, found a lot, but all of them are not what I need.
So, I have a pretty simple menu with ListView and a file for items with TextView. I want to set Segoe-Print font for items in my menu, I know, that I need adapter, but I can't do it. Help!!!
menu.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:id="#+id/menu_top"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/menu_top">
</LinearLayout>
<ListView
android:id="#+id/ListView_Menu"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/fon_android"
android:divider="#drawable/menu_line"
android:textStyle="bold" >
</ListView>
</LinearLayout>
menu_item.xml:
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/menu_prop"
android:layout_width="fill_parent"
android:textSize="19px"
android:text="test string"
android:layout_gravity="left"
android:layout_height="wrap_content"
android:shadowRadius="5"
android:textColor="#color/menu_color"
android:shadowDy="3"
android:shadowDx="3" />
A part of Main_Menu.java:
public class Main_menu extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menu);
ListView menuList = (ListView) findViewById(R.id.ListView_Menu);
String[] items = {
getResources().getString(R.string.system),
getResources().getString(R.string.convert),
getResources().getString(R.string.forks),
getResources().getString(R.string.margin)};
ArrayAdapter<String> adapt = new ArrayAdapter<String>(this,R.layout.menu_item, items);
menuList.setAdapter(adapt);
}
CustomAdapter.java:
public class CustomAdapter extends ArrayAdapter<String> {
public CustomAdapter(Context context, int resource, String[] objects) {
super(context, resource, objects);
// TODO Auto-generated constructor stub
}
public View getView (int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
TextView textView = (TextView) view.findViewById(R.id.menu_prop);
Typeface font = Typeface.createFromAsset(getAssets(), "segoe_print.ttf");
textView.setTypeface(font);
return textView;
}
private AssetManager getAssets() {
// TODO Auto-generated method stub
return null;
}
}
The font doesn't change...
view.txtViewTitle.setTypeface(Typeface.createFromAsset(parent
.getContext().getAssets(), "fonts/DroidSerif.ttf"));
here is code for custom adapter:
private class CostumiseAdapter extends ArrayAdapter<item>{
public CostumiseAdapter(ArrayList<item> items) {
super(getActivity(), 0, items);
}
#Override
public View getView(int position, View convertView, ViewGroup parent){
if(convertView == null){
convertView = getActivity().getLayoutInflater().inflate(R.layout.scroll_fragment, null);
}
Item item = getItem(position);
TextView text = (TextView) convertView.findViewById(R.id.text_view);
text.setText(item.mString);
RadioButton b1 = (RadioButton) convertView.findViewById(R.id.radio_b1);
b1.setChecked(item.mB1);
RadioButton b2 = (RadioButton) convertView.findViewById(R.id.radio_b2);
b2.setChecked(item.mB2);
CheckBox cB = (CheckBox) convertView.findViewById(R.id.check_box);
cB.setChecked(item.mB2);
return convertView;
}
}
I've take it from http://androide-examples.blogspot.com/2013/11/android-scroll-list.html see for the full example.
In this example are some semantik mistakes. So you have to fix some items to Items (capitalise)...
You need to create a custom adapter for setting custom font. Here is the minimal code :
public class CustomAdapter extends ArrayAdapter<String> {
//Contructor here
public View getView (int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
TextView textView = (TextView) view.findViewById(R.id.myTextView);
// Here you set the typeface as you do for the TextView
textView.setTypeFace(....);
}
}
That should provide you the custom font for your Listview.
I found a desition!
Well, first of all I create another class for Adapter:
public class Typefaces {
private static final Hashtable<String, Typeface> cache = new Hashtable<String, Typeface>();
public static Typeface get(Context c, String name) {
synchronized (cache) {
if (!cache.containsKey(name)) {
String path = "fonts/"+name;
try {
Typeface t = Typeface.createFromAsset(c.getAssets(), path);
cache.put(name, t);
} catch (Exception e) {
e.printStackTrace();
}
}
return cache.get(name);
}
}
}
Then in the main Adapter I added two strings:
Typeface tf = Typefaces.get(getContext(), "tahoma.ttf");
holder.txtTitle.setTypeface(tf);
That's all! It's working! )) Thank you all for help and answers.
try in xml:
android:fontFamily="somefont.ttf"
From android 4.1+ the following font are available: http://robotofont.com/
android:fontFamily="sans-serif"
android:fontFamily="sans-serif-thin"
android:fontFamily="sans-serif-light"
android:fontFamily="sans-serif-condensed"
you can also set font programaticly:
TextView t = (TextView) findViewById(R.id.name);
Typeface font = Typeface.createFromAsset(getAssets(),"font/somefont.ttf");
t.setTypeface(font);
put the font file in a folder...