gpt4 book ai didi

react-native - 如何在 React Native Top Navigation 中正确更改 indicatorStyle 的宽度?

转载 作者:行者123 更新时间:2023-12-05 02:08:30 25 4
gpt4 key购买 nike

我希望能够减少顶部导航栏中 indicatorStyle 的宽度以实现以下结果:

enter image description here

但是每当我尝试减小条的宽度时,我都无法将其正确居中。这是我目前拥有的;

enter image description here

下面是我的代码:

import React from 'react';
import { createAppContainer } from 'react-navigation';
import {createMaterialTopTabNavigator } from 'react-navigation-tabs';
import Colors from '../constants/Colors';
import Tab1 from '../screens/tab1';
import Tab2 from '../screens/tab2';


const HomeTab = createMaterialTopTabNavigator({
TAB1: Tab1,
TAB2: Tab2,
},
{
tabBarOptions: {
activeTintColor: 'black',
inactiveTintColor: 'gray',
labelStyle: { fontSize: 14, fontWeight:"700" },
style: { backgroundColor: Colors.mainBackground, elevation: 0, shadowOpacity: 0, borderBottomWidth:2, borderColor:'#ccc' },
indicatorStyle: { backgroundColor: 'blue', width:100},

},
}

);

感谢您的帮助!真的很感激:)

最佳答案

为了使其准确居中,我使用了 Dimensions API 来获取精确的宽度和偏移量。

const totalWidth = Dimensions.get("screen").width;

然后

indicatorStyle: {
width: totalWidth / 4,
left: totalWidth / 8,
}

关于react-native - 如何在 React Native Top Navigation 中正确更改 indicatorStyle 的宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60821904/

25 4 0
文章推荐: php - 如何使用搜索和替换通过 API 修改 Google Docs 文档?
文章推荐: python-3.x - 如何清除pyqt5中qtextbrowser的内容?
文章推荐: javascript - 警告 : Expected server HTML to contain a matching in
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com