我在Android中有一个ListActivity.每行只是一个用一些资源启动另一个活动的项目.默认情况下,这当然是TextView.
我想(并且"我想",我的意思是"客户坚持")TextView看起来像一个按钮.如果我实际上使它们成为按钮,则默认列表单击处理程序不再起作用 - 即使它们不可聚焦 - 所以我必须编写代码来手动膨胀包含按钮的视图并设置单击处理程序.
有没有什么方法我可以让TextView看起来像一个按钮没有任何Button的行为?
Fem*_*emi 10
您应该只能在布局XML文件中设置样式.
有关内置平台样式的列表,请参见http://developer.android.com/reference/android/R.style.html.不确定它的效果如何,但它相当容易做到.试试这个:
<TextView android:layout_height="wrap_content" style="@android:style/Widget.Button" android:layout_marginRight="5sp" android:text="" android:layout_width="fill_parent"></TextView>
Run Code Online (Sandbox Code Playgroud)
编辑:问题是默认按钮样式设置android:clickable属性.尝试添加android:clickable属性并将其设置为false:
<TextView android:layout_height="wrap_content" style="@android:style/Widget.Button" android:layout_marginRight="5sp" android:text="" android:clickable="false" android:layout_width="fill_parent"></TextView>
Run Code Online (Sandbox Code Playgroud)