【问题标题】:how to set tablayout icon using fontawesome如何使用 fontawesome 设置 tablayout 图标
【发布时间】:2018-03-17 03:07:53
【问题描述】:

我是 android 的初学者。我正在为图标使用 font-awesome 库。我想使用 view pager 在tablyout 中使用 font-awesome 设置图标

【问题讨论】:

  • 你能发布你的代码吗?

标签: android font-awesome android-tablayout


【解决方案1】:

创建一个名为 custom_tab.xml 的 xml 布局

custom_tab.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/tab"
    />

现在使用下面的代码设置选项卡布局的字体

TextView tabOne = (TextView) LayoutInflater.from(this).inflate(R.layout.custom_tab, null);
tabOne.setText("&#xf1fe;");
Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/fontawesome-webfont.ttf");
tabOne.setTypeface(typeface);
tabLayout.getTabAt(0).setCustomView(tabOne);

How to Use FontAwesome in an Android App

【讨论】:

  • 实现上述并工作,不幸的是,图标左对齐。如何保持图标居中对齐??
猜你喜欢
  • 1970-01-01
  • 2019-09-08
  • 2016-03-26
  • 1970-01-01
  • 1970-01-01
  • 2021-11-27
  • 1970-01-01
  • 1970-01-01
  • 2019-11-27
相关资源
最近更新 更多