23

I'm trying to use ActionBarSherlock in one specific activity which I've declared in the Manifest like this:

<activity
        android:name=".activities.Bla"
        android:screenOrientation="portrait"
        android:theme="@style/Theme.Sherlock" />

My Activity code is this:

public class Bla extends SherlockFragmentActivity implements ActionBar.OnNavigationListener {

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.bla);
    getSupportActionBar().setTitle("");
    getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);

    Context context = getSupportActionBar().getThemedContext();
    ArrayAdapter<CharSequence> list =
        ArrayAdapter.createFromResource(context, R.array.cartaz_filters, R.layout.actionbar_spinner_item);
    list.setDropDownViewResource(R.layout.actionbar_spinner_dropdown_item);
    getSupportActionBar().setListNavigationCallbacks(list, this);
  }

  @Override
  public boolean onNavigationItemSelected(int itemPosition, long itemId) {
    return true;
  }
}

However, every time I run this in an Android 2.1 I get the following error:

E/ResourceType(9672): Style contains key with bad entry: 0x01000000

I think this might be related with this question: Read Newer Theme Attributes On Older Platform but I don't know how to solve it.

Any suggestions? Thanks!

4

1 回答 1

52

这是因为您正在使用运行应用程序的平台上不存在的主题属性。尽管它添加了巨大的红色错误日志,但它更像是一个警告,因为它不会影响其他属性。较新的属性永远不会在较旧的平台上读取。

我的相关问题是我试图不必要求 ABSv4 使用镜像属性。

如果您真的想摆脱错误,您可以创建两组样式。一种values/用于兼容性操作栏,另一种values-v14/用于使用本机操作栏的前缀属性。

请,请,请,请不要使用maxSdkVersion。改为使用targetSdkVersion

于 2012-03-13T20:25:54.593 回答