【问题标题】:Android -- put space between tab title and icon?Android - 在选项卡标题和图标之间放置空格?
【发布时间】:2014-05-25 21:38:27
【问题描述】:

这显然太接近了。缺少编辑图标文件,如何更改?

下面的代码是 C# 代码(通过 Xamarin),但我相信我会很好地理解 Java 答案。

Android.App.ActionBar.Tab droidTab = this.ActionBar.NewTab();
droidTab.SetIcon(drawableBitmap);
droidTab.SetText(someString);

【问题讨论】:

  • 如果你真的不想编辑图标,我想你可以在字符串的开头添加一个空格
  • 我使用了“文本前的空格”技巧。有用。正如他们所说,“有时是最简单的答案……”。 :)

标签: android tabs padding margins


【解决方案1】:

使用默认 API 无法做到这一点。但是,您可以设置自定义视图。将TextView 与复合Drawable 一起使用,您可以使用setCompoundDrawablePadding 设置Drawable 填充:

TextView textView = new TextView(mContext);
textView.setText(someString);
textView.setCompoundDrawables(mDrawable, null, null, null);
textView.setCompoundDrawablePadding(mPaddingDp);

droidTab.setCustomView(textView);

【讨论】:

  • 对于图像,您应该致电:setCompoundDrawablesWithIntrinsicBounds()
【解决方案2】:

Check the image 你可以使用下面的代码来实现图标和标题之间的间距

    TextView tabOne = (TextView) LayoutInflater.from(getContext()).inflate(R.layout.custom_tab, null);
    tabOne.setText(tab1);
    tabOne.setCompoundDrawablesWithIntrinsicBounds(R.drawable.dash_today,0, 0, 0);
    tabOne.setCompoundDrawablePadding(icon_dp);
    tabLayout.getTabAt(0).setCustomView(tabOne);

    TextView tabTwo = (TextView) LayoutInflater.from(getContext()).inflate(R.layout.custom_tab, null);
    tabTwo.setText(tab2);
    tabTwo.setCompoundDrawablesWithIntrinsicBounds(R.drawable.dash_pipe,0, 0, 0);
    tabTwo.setCompoundDrawablePadding(icon_dp);
    tabLayout.getTabAt(1).setCustomView(tabTwo);`

【讨论】:

    猜你喜欢
    • 2018-02-18
    • 1970-01-01
    • 2016-10-25
    • 1970-01-01
    • 1970-01-01
    • 2019-03-22
    • 1970-01-01
    • 2015-08-21
    • 2011-12-15
    相关资源
    最近更新 更多