Android row column onSelect background

<!--Even row -->
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">        
    <item android:state_pressed="true" android:drawable="@color/selected" />
    <item android:state_selected="true" android:drawable="@color/selected" />
    <item android:state_focused="true" android:drawable="@color/selected" />
    <item android:drawable="@color/even_row" />
    <item android:state_selected="true" android:state_focused="false" android:state_pressed="false" android:drawable="@color/even_row" />
</selector>


<!--Odd row -->
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@color/selected" />
<item android:state_selected="true" android:drawable="@color/selected" />
<item android:state_focused="true" android:drawable="@color/selected" />
<item android:state_selected="true" android:state_focused="false" android:state_pressed="false" android:drawable="@android:color/transparent" />
</selector>


java code:

for (String data:rowData){
			   
				   TextView col = new TextView(context);
				   col.setTextAlignment(TextView.TEXT_ALIGNMENT_CENTER);
				   col.setText(data);
				   col.setTextSize(24);
				   if (clickable){
					   if (table.getChildCount()%2==0)
						   col.setBackgroundResource(R.drawable.table_selector_odd);
					   else
						   col.setBackgroundResource(R.drawable.table_selector_even);
				   }
				   
			   row.addView(col, col1Params);
		   }



Ant Design Vue 中的 Table 组件的 `row-select` 功能,当使用 `onSelect` 回调处理全选操作时,可能会遇到默认禁用了所有行被选中的情况。这是因为 Ant Design 对表格的全选功能做了预设,通常会有一个全局的 "取消全选" 的逻辑。 如果你想要实现在 `onSelect` 中实现全选功能,你需要手动控制这个选择状态。可以创建一个全局变量来存储当前是否全部选中,然后在 `onSelect` 中更新这个变量,并根据变量的值控制每行的 `selected` 属性。 以下是一个简单的示例: ```javascript <template> <a-table :data="tableData" :select-row-keys="selectAllKeys"> <!-- ... --> <a-column type="selection" /> <!-- ... --> <template slot-scope="scope"> <span @click.stop v-if="selectAll">{{ selectAll ? '取消全选' : '全选' }}</span> <!-- 或者直接绑定到行的 selected 属性上 --> <span :class="{ selected: scope.$index === selectedIndex }" @click="toggleSelection(scope.$index)"> {{ scope.row.name }} </span> </template> </a-table> </template> <script> export default { data() { return { tableData: [], // 表格数据 selectAllKeys: [], // 存储当前选中的行索引 selectAll: false, selectedIndex: null, }; }, methods: { toggleSelection(index) { if (this.selectAll) { this.selectAllKeys = []; } else { this.selectAllKeys.push(index); } this.selectAll = !this.selectAll; }, }, // ...其他生命周期钩子和事件处理 }; </script> ``` 在这个例子中,`toggleSelection` 方法用于切换全选状态,当你点击 "全选" 或 "取消全选" 按钮时,它会更新 `selectAllKeys` 和 `selectAll` 变量。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值