我有抽屜和堆疊導航器。我禁用了抽屜和堆疊導航器的標題。并創建自己的標題組件,但我無法擺脫自定義標題組件的邊緣。
[截圖] https://i.stack.imgur.com/5jWv3.png
const styles = StyleSheet.create({
header: {
backgroundColor: 'purple',
width: '100%',
height: '100%',
flexDirection: 'row',
alignItems: 'center',
},
headerText: {
fontWeight: 'bold',
fontSize: 21,
letterSpacing: 1,
paddingLeft: 45,
paddingBottom: 2,
},
icon: {
fontSize: 30,
color:"white",
position: 'absolute',
zIndex: 3,
}});
return (
<View style={styles.header}>
<View style={styles.header}>
<MaterialIcons style={styles.icon} name="menu" onPress={openMenu}/>
<Text style={styles.headerText}>{titleName}</Text>
</View>
</View>
)
uj5u.com熱心網友回復:
這是您的標頭組件。您是否檢查過主容器在螢屏中是否沒有 paddingHorizo??ntal?
uj5u.com熱心網友回復:
解決方案 #1 更改:
return (
<View style={styles.header}>
<View style={styles.header}>
<MaterialIcons style={styles.icon} name="menu" onPress={openMenu}/>
<Text style={styles.headerText}>{titleName}</Text>
</View>
</View>
)
到:
return (
<View style={styles.header}>
<MaterialIcons style={styles.icon} name="menu" onPress={openMenu}/>
<Text style={styles.headerText}>{titleName}</Text>
</View>
)
解決方案#2
import {Dimensions} from 'react-native'
let width=Dimensions.get('screen').width
let height=Dimensions.get('screen').height
然后:
const styles = StyleSheet.create({
header: {
backgroundColor: 'purple',
width: width,
height: height,
flexDirection: 'row',
alignItems: 'center',
},
})
uj5u.com熱心網友回復:
我解決了在 Web 上打開應用程式以查看父元素樣式的問題。在這種情況下,我的父元素是 <Stack.screen> 主頁選項卡。
我剛剛檢查了網頁上的樣式
marginLeft: 16,
marginRight: 16,
maxWidth: 470,
并覆寫這些樣式
marginLeft: 0,
marginRight: 0,
maxWidth: '100%',
求解結果截圖
<Stack.screen
options={{headerBackgroundContainerStyle: {
marginLeft: 0,
marginRight: 0,
maxWidth: '100%'
}
}}
/>
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/475090.html
