Android 操作栏选项卡,一起设置图标和文本样式 [英] Android Action Bar Tabs, Styling the Icon and Text together

查看:25
本文介绍了Android 操作栏选项卡,一起设置图标和文本样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,有我当前标签栏的图像

Firstly, there is the image of my current tab bar

我想要的是将图像对齐到最左边,同时保持文本居中或将图像移动到居中文本的顶部.

What I want is either aligning the images to very left, while keeping the text centered or moving the images on top of the text centered.

这是我添加文本的方式:

Here is how I add the texts:

var tab = this.ActionBar.NewTab ();            
tab.SetText (tabText);
tab.SetIcon (iconResourceId);

这是我的相关 style.xml 条目:

Here is my relevant style.xml entries:

<style name="Theme.Discover" parent="@android:style/Theme.Holo.Light">
    <item name="android:actionBarStyle">@style/MyActionBar</item>
    <item name="android:actionBarTabStyle">@style/MyActionBarTabStyle</item>
    <item name="android:actionBarTabTextStyle">@style/MyActionBarTabText</item>
    <item name="android:actionMenuTextColor">#ffffff</item>
    <item name="android:windowBackground">@drawable/bg</item>
</style>

<style name="MyActionBarTabStyle" parent="@android:style/Widget.Holo.Light.ActionBar.TabView">
    <item name="android:background">@drawable/action_tab_selector</item>
</style> 

<!-- ActionBar tabs text styles -->
<style name="MyActionBarTabText"
       parent="@android:style/Widget.Holo.ActionBar.TabText">
    <item name="android:textColor">#ffffff</item>
</style>

我也能看懂 java 代码,所以如果你不熟悉 Xamarin,我仍然很欣赏 java 示例和答案.

I can understand java code too so if you are not familiar with Xamarin, I still appreciate the java examples&answers.

推荐答案

我的解决方案并不完美,但将图标移到文本上方是我目前所做的,也许可以帮到你.

My solution isn't perfect, but to move the icons above the text here is what I have so far, which might be able to help you.

>

TabLayout.axml

<?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="vertical">
    <ImageView
        android:id="@+id/tab_icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@android:color/transparent" />
    <TextView
        android:id="@+id/tab_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</LinearLayout>

MainActivity.cs

 void AddTabToActionBar(int labelResourceId, int iconResourceId)
        {
            var tab = this.ActionBar.NewTab();
            tab.SetCustomView(Resource.Layout.Tablayout);
            tab.CustomView.FindViewById<ImageView>(Resource.Id.tabImage).SetImageResource(iconResourceId);
            tab.CustomView.FindViewById<TextView>(Resource.Id.tabText).SetText(labelResourceId);
            tab.TabSelected += TabOnTabSelected;
            ActionBar.AddTab(tab);

        }

这篇关于Android 操作栏选项卡,一起设置图标和文本样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆