【问题标题】:Remove left space in title view xamarin forms删除标题视图 xamarin 表单中的左侧空格
【发布时间】:2020-07-04 19:53:20
【问题描述】:

我在删除标题视图中多余的左侧空格时遇到问题,如下图所示please see the screenshot here

Ps:我使用的是标签页,那个栏是导航标题视图。

【问题讨论】:

  • 内边距是内置的
  • 我找到了使用 InsetPadding medium.com/@prateekrm/… 的解决方案,但没有详细信息,所以我不知道如何处理它
  • 但是使用自定义渲染器@Greggz 没有什么是不可能的
  • 您发送的链接不适用于自定义渲染器。它只是创建自己的“导航栏”。只需按照发布说明进行操作
  • 他只是在一行中提到了 InsetPadding 但没有显示示例@Greggz

标签: xamarin.forms xamarin.android navigationbar tabbedpage titleview


【解决方案1】:

在您的 Android 部分的Toolbar.xml 中设置下面的 xml。

app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:contentInsetStartWithNavigation="0dp" 

不要忘记在Toolbar.xaml 中添加应用的命名空间。

xmlns:app="http://schemas.android.com/apk/res-auto"

并检查下面的代码,它需要添加到MainActivity.cs

ToolbarResource = Resource.Layout.Toolbar;

用法:

<NavigationPage.TitleView>
    <Label Text="Repositories" />
</NavigationPage.TitleView>

【讨论】:

  • 谢谢你救了我的命(虽然我失去了整整 7 个小时的搜索时间)
  • 好的,现在好像可以了。我认为只需从 PCL 和 android 项目中删除所有 bin 和 obj 文件夹。
  • 对我不起作用...知道为什么吗?这是我的 Toolbar.xml:&lt;android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" ... app:contentInsetLeft="0dp" app:contentInsetStart="0dp" app:contentInsetStartWithNavigation="0dp" android:padding="0dp" /&gt;
  • android.support.v7.widget.Toolbar 更改为androidx.appcompat.widget.Toolbar
  • 确实!!!同样的问题here 详细解释了您的建议。上面的解决方案对我不起作用
【解决方案2】:

另一种无需自定义 xml 布局的解决方案适用于那些已经创建了 IShellToolbarAppearanceTracker 子类化 ShellToolbarAppearanceTracker 的人:

        public override void SetAppearance(Toolbar toolbar, IShellToolbarTracker toolbarTracker, ShellAppearance appearance)
        {
            base.SetAppearance(toolbar, toolbarTracker, appearance);

            toolbar.SetContentInsetsAbsolute(0,0);
        }

这里讨论原生问题:

Toolbar extra left inset/padding

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-10
    • 2017-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-27
    • 1970-01-01
    相关资源
    最近更新 更多