android - 自定义操作栏布局中按钮的 sherlock 操作项样式

标签 android android-layout actionbarsherlock

有没有办法将 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/

相关文章:

android - fragment 中的 findViewById

java - 在 Android TextView 中对齐文本和图标

android - ConstraintLayout ListView RTL 有些行不是RTL

android - 更改选项卡标题的字体 - ActionBarSherlock

android - 在 SearchView 上强制图标化

android - 如何在 Android 中添加 google-services.json?

Android 媒体播放器 IllegalStateException

android - Greendroid 或 ActionbarSherlock - 设置

Android:更改所有 ListView 行中项目的可见性

android - 我在哪里可以找到一些好的 Android UI 示例?