android - 如果数据存在,则更改反应本机标头的按钮
问题描述
我想检查数据是否存在,如果数据存在则显示红色按钮,如果没有数据则显示蓝色按钮。我试图这样做,但它不起作用。例如,如果有任何 DM, Instagram转到 DM 的按钮,按钮会随着 DM 的未读数量变为不同的颜色,如果没有 Dm,则它是简单的按钮。
static navigationOptions = ({ navigation }) => {
const { params = {} } = navigation.state;
const { notifications } = this.props.notification;
return {
headerRight: (
<View>
{
(notifications.length > 0) ? (
<TouchableOpacity onPress={() => params.handleSave()}>
<Badge>
<Text>{notifications.length}</Text>
</Badge>
</TouchableOpacity>
) : (
<TouchableOpacity onPress={() => params.handleSave()}>
<Ionicons
name="ios-notifications-outline"
style={{ paddingRight: 15 }}
size={24}
color="white"
/>
</TouchableOpacity>
)
}
</View>
)
};
}
解决方案
创造两种不同的风格和条件
style={[navigation.state.yourstate ? styles.selectedButtonStyle : styles.normalButtonStyle]}
推荐阅读
- svg - 当svg文档的单词之间出现空格时如何将文本换行
- hive - 将pyspark中的一列字符串数组转换为一列中的多行
- javascript - 此函数应以 id、名称和电子邮件作为参数,并返回具有 `id`、`name` 和 `email` 属性的对象
- mongodb - Mongo Query - 过滤嵌套数组并返回不包含特定字段的文档
- python - Slack API - 用于检索斜杠命令的队列
- c# - .net 核心控制器动作,返回静态 html 页面
- windows - 如何从句柄中检索组件名称?
- mysql - MySQL/JPA 字段没有默认值错误,即使该字段位于类层次结构中的不同类中
- three.js - 设置 Freesurfer inflated 的网格坐标偏移
- sql - 将字符串拆分为列