有没有办法将 sherlock 操作项样式(默认触摸反馈和长按反馈以及点击区域 - 宽度/高度)应用于自定义操作栏布局中的按钮?
src/MainActivity.java
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getSupportActionBar().setCustomView(R.layout.actionbar_main);
res/layout/actionbar_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<!-- Home button -->
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="12dp"
android:background="@drawable/ic_home"
android:contentDescription="@string/ic_home"
android:onClick="clickButtonHome" />
<!-- Centered text -->
<TextView
android:id="@+id/add_actionbar_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/title_activity_main"
android:textAppearance="?android:attr/textAppearanceMedium" />
<!-- Cancel button -->
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="12dp"
android:background="@drawable/ic_cancel"
android:contentDescription="@string/ic_cancel"
android:onClick="clickButtonHome" />
</RelativeLayout>
最佳答案
Widget.Sherlock.ActionButton
用于 ImageButton
的样式。要实现长按 toast 效果,您需要使用 Roman Nurik 的 CheetSheet类。
为了将来引用,所有 ActionBarSherlock 样式和主题都具有与 native 样式和主题相同的命名约定,但使用“Sherlock”而不是“Holo”。例如,
Widget.Holo.ActionButton
变为Widget.Sherlock.ActionButton
Theme.Holo.Light.DarkActionBar
变为Theme.Sherlock.LightDarkActionBar
TextAppearance.Holo.Widget.ActionBar.Title
变为TextAppearance.Sherlock.Widget.ActionBar.Title
关于android - 自定义操作栏布局中按钮的 sherlock 操作项样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14457312/