当前位置: 首页 > 知识库问答 >
问题:

Xamarin中选项卡式页面的标题截断。形式

闻人修平
2023-03-14

在Android中,选项卡式页面标题在选项卡式页面中被截断

但在iOS设备上运行良好

我正在使用这个代码

public Tabbar()
        {
            //this.BarTextColor = Color.Maroon;
            // New Feed
            var navigationNewFeed = new NavigationPage(new NewFeedView());
            navigationNewFeed.Title = "News Feed";
            navigationNewFeed.Icon = "news";
            Children.Add(navigationNewFeed);

            // Volunteer View
            var navigationPageVolunteer = new NavigationPage(new VolunteerView());
            navigationPageVolunteer.Icon = "Volunteer";
            navigationPageVolunteer.Title = "Volunteer";
            Children.Add(navigationPageVolunteer);


            // LAH View
            var navigationPageLAH = new NavigationPage(new LAHView());
            navigationPageLAH.Icon = "lah";
            navigationPageLAH.Title = "LAH";
            Children.Add(navigationPageLAH);



            // Notification View
            var navigationPageNotification = new NavigationPage(new NotificationView());
            navigationPageNotification.Icon = "notification";
            navigationPageNotification.Title = "Notification";
            Children.Add(navigationPageNotification);


            // Account View
            var navigationPageAccount = new NavigationPage(new AccountView());
            navigationPageAccount.Icon = "account";
            navigationPageAccount.Title = "Account";
            Children.Add(navigationPageAccount);


        }

共有3个答案

甄煜
2023-03-14

基本上,在android中,默认情况下,文本以大写字母显示,尽管您以大写字母键入第一个字母,以下文字以小写字母键入(例如,按钮文本“Accept”显示为Accept)。

要覆盖它并在键入时显示(即接受),请在应用于Android活动的主题文件(例如在YourProject.Android/Resources/values/styles.xml中)中包含这一行

<style name="MyTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    ............
    <item name="android:textAllCaps">false</item>
</style>

感谢为什么我的按钮文本被迫在Lollipop上全部大写字母中的答案?

编辑:如果你缺少标签标题,你可以使用下面的代码来解决,因为它很好地解决了我的问题!

using Android.Content;
using Android.Support.Design.Internal;
using Android.Views;
using FixedTabbedPage.Droid.CustomRenderers;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
using Xamarin.Forms.Platform.Android.AppCompat;

[assembly: ExportRenderer(typeof(TabbedPage), typeof(CustomTabbedPageRenderer))]
namespace FixedTabbedPage.Droid.CustomRenderers
{
    public class CustomTabbedPageRenderer : TabbedPageRenderer
    {
        public CustomTabbedPageRenderer(Context context) : base(context) { }

        protected override void OnElementChanged(ElementChangedEventArgs<TabbedPage> e)
        {
            base.OnElementChanged(e);

            if (ViewGroup != null && ViewGroup.ChildCount > 0)
            {
                BottomNavigationMenuView bottomNavigationMenuView = FindChildOfType<BottomNavigationMenuView>(ViewGroup);

                if (bottomNavigationMenuView != null)
                {
                    var shiftMode = bottomNavigationMenuView.Class.GetDeclaredField("mShiftingMode");

                    shiftMode.Accessible = true;
                    shiftMode.SetBoolean(bottomNavigationMenuView, false);
                    shiftMode.Accessible = false;
                    shiftMode.Dispose();

                    for (var i = 0; i < bottomNavigationMenuView.ChildCount; i++)
                    {
                        var item = bottomNavigationMenuView.GetChildAt(i) as BottomNavigationItemView;
                        if (item == null) continue;                         

                        item.SetShiftingMode(false);
                        item.SetChecked(item.ItemData.IsChecked);
                    }

                    if (bottomNavigationMenuView.ChildCount > 0) bottomNavigationMenuView.UpdateMenuView();
                }
            }
        }

        private T FindChildOfType<T>(ViewGroup viewGroup) where T : Android.Views.View
        {
            if (viewGroup == null || viewGroup.ChildCount == 0) return null;

            for (var i = 0; i < viewGroup.ChildCount; i++)
            {
                var child = viewGroup.GetChildAt(i);

                var typedChild = child as T;
                if (typedChild != null) return typedChild;

                if (!(child is ViewGroup)) continue;

                var result = FindChildOfType<T>(child as ViewGroup);

                if (result != null) return result;
            }

            return null;
        }
    }
}

参考:1)在Xamarin Forms 3.1中,当使用具有4个选项卡的选项卡式页面时,如何防止Android上选项卡栏的“滑动”效果?

2)https://forums . xa marin . com/discussion/Comment/361462 # Comment _ 361462

感谢jezh和J.Aguilar

希望这有帮助..

琴修为
2023-03-14

您可以使用自定义样式并更改选项卡中文本的大小。如何对选项卡使用自定义样式。

并更改样式:

<style name="CustomTab"
       parent="@android:style/Widget.Holo.ActionBar.TabText">
    <item name="android:textSize">5sp</item>
</style>
江正德
2023-03-14

尝试在您的Android XF项目上通过< code>Tabbar.axml设置更小的文本大小,添加app:tabTextAppearance= "?Android:attr/text appearance small "

<android.support.design.widget.TabLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/sliding_tabs" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="?attr/colorPrimary" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
    app:tabTextAppearance="?android:attr/textAppearanceSmall"
    app:tabIndicatorColor="@android:color/white" 
    app:tabGravity="fill" 
    app:tabMode="fixed" />
 类似资料:
  • 我试图修改JavaFX8中的TabPage控件,使其向视口显示当前选定选项卡前面(右边)的一些选项卡,或者如果选定选项卡位于标题的最左边,它会显示当前选项卡前面附近的选项卡。 现在怎么样了: 我想让它表现得像: 当用户选择索引X的选项卡时,选项卡窗格标题显示附近的另外2或3个选项卡。 谢谢你的阅读。

  • 使用TabsLayout实现了一个选项卡活动,但现在活动的标题没有显示在工具栏上,尝试了各种我在internet上找到的修补程序,但似乎都不起作用。 活动得XML: onCreate:受保护的空onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(r.layout.activity

  • 实际行为 预期行为 至于我使用的代码,主加载了一个,其中调度页是真正的罪魁祸首,扩展了Xamarin.Forms.TabbedPage。SelectedPage被正确设置(加载正确的contentpage),但选项卡没有突出显示。 null

  • 问题内容: 我正在尝试“强制” Safari或IE7 使用新标签 打开新页面。 以编程方式,我的意思是: 问题答案: 您不能直接控制它,因为它是由Internet Explorer用户控制的选项。 使用Window.open用不同的窗口名称打开页面会像一个弹出窗口,一个新的浏览器窗口中打开 或 在新标签页中打开,如果用户配置的浏览器这样做。

  • 我使用TabLayout与Viewpager和有3个标签。我正在使用FragmentPagerAdapter来设置选项卡和它的片段。 我只想加载第一个选项卡的片断时,它是默认选择,并希望加载其他选项卡的片断在一个新的活动。 我尝试在位置1和位置2的情况下从getItem方法返回null,但它给出了异常。 提前多谢。

  • 他们使用术语截断多项式来表示:。他们使用什么模式将此扩展到此?