1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > Android 字体没效果 android - 更改选项卡的字体 fontFamily不起作用 - SO中文参考 - www.soinside.com...

Android 字体没效果 android - 更改选项卡的字体 fontFamily不起作用 - SO中文参考 - www.soinside.com...

时间:2019-12-30 19:14:26

相关推荐

Android 字体没效果 android - 更改选项卡的字体 fontFamily不起作用 - SO中文参考 - www.soinside.com...

我在Xamarin.Forms应用程序(在android上)中为标签定义自定义字体时遇到问题。

The Tabbar.xml<?xml version="1.0" encoding="utf-8"?>

xmlns:app="/apk/res-auto"

android:id="@+id/sliding_tabs"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center_horizontal"

android:background="?attr/colorPrimary"

android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"

app:tabTextAppearance="@style/TabbarTitleText"

app:tabTextColor="@android:color/white"

app:tabSelectedTextColor="@android:color/white"

app:tabIndicatorColor="@android:color/white"

app:tabGravity="fill"

app:tabMode="fixed" >

我试图放置textview但没有编译。

我在styles.xml中创建的样式已应用,但fontFamily属性除外

15dp

fonts/Futura Book.ttf

false

所有参数正确吗?特别是parent =

如果我使用自定义渲染器,则它不起作用,因为在TabLayout中没有要检测的子元素。

对于我的工具栏,它可以工作,因为TextView接收了自定义渲染参数。

xmlns:app="/apk/res-auto"

android:id="@+id/toolbar"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:textColor="@android:color/white"

android:theme="@style/MyActionBar"

android:background="@drawable/custom_background_bar"

android:elevation="3dp">

style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"

android:textColor="@android:color/white"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:gravity="center_vertical"

android:id="@+id/toolbar_title" />

。public class MyToolBarRenderer : NavigationPageRenderer

{

public MyToolBarRenderer(Context context) : base(context)

{

}

private Support.Toolbar _toolbar;

public override void OnViewAdded(Android.Views.View child)

{

base.OnViewAdded(child);

if (child.GetType() == typeof(Support.Toolbar))

_toolbar = (Support.Toolbar)child;

}

protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)

{

base.OnElementPropertyChanged(sender, e);

var page = this.Element as NavigationPage;

if (page != null && _toolbar != null)

{

Typeface tf = Typeface.CreateFromAsset(Android.App.Application.Context.Assets, "fonts/Futura Book.ttf");

TextView title = (TextView)_toolbar.FindViewById(Resource.Id.toolbar_title);

title.SetText(page.CurrentPage.Title, TextView.BufferType.Normal);

title.SetTypeface(tf, TypefaceStyle.Normal);

}

}

}

我的所有视图都是NavigationPages,而不是任何TabbedPage。

在App.xaml.cs中,我有这个MainPage = new NavigationPage(new MainPage())

然后在主页中switch (Device.RuntimePlatform)

{

case Device.iOS:

centerPage = new NavigationPage(new Center_Main())

{

Title = TitleCenter

};

......

break;

default:

centerPage = new Center_Main()

{

Title = TitleCenter

};

rightPage = new Right_Main()

{

Title = TitleRight

};

.......

break;

}

然后每个xaml都是一个ContentPage。我基本上从一开始就创建了一个Master Detail项目。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。