我怎么能突出显示单击表格行? [英] How can I highlight the table row on click ?
问题描述
由于我的项目,要求我必须强调的onClick上的表行。有没有办法做到这一点?或请建议我的选择吗?
As my project requirement i have to highlight the table row on onClick. There is any way to do this? Or please suggest me the alternative?
推荐答案
如果你想用股票对点击的亮点就像你得到一个通用的ListView,你要设置的每个行的背景是机器人:背景=@机器人:可绘制/ list_selector_background
If you want to use the stock on click highlight like you get with a generic ListView, you want to set the background of each row to be android:background="@android:drawable/list_selector_background"
下面是一个例子:
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="0">
<TableRow
android:id="@+id/first_row"
android:background="@android:drawable/list_selector_background" >
... row content ...
</TableRow>
</TableLayout>
然后在code,
Then in code,
TableRow firstRow = (TableRow) findViewById(R.id.first_row);
firstRow.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO: do your logic here
}
}
和你应该得到的一大亮点,能排,就像在ListView ...
And you should get a highlight-able row just like in a ListView...
编辑: 上面给你的默认主题的列表背景选择。如果你想更通用的选择(比如当用户触摸排料设计选择器)使用这样的:
Above will give you the default theme's list background selector. If you want the more generic selector (like the material design selector when the user touches a row) use this:
android:background="?android:attr/selectableItemBackground"
也适用于多只TableRows。你应该能够做到这一点的几乎所有普通窗口小部件连接了onClickListener(TextViews,按钮等)。
Also this applies to more than just TableRows. You should be able to do this on almost any generic widget with an onClickListener attached (TextViews, Buttons, etc).
这篇关于我怎么能突出显示单击表格行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!