我刚刚获得了与 ActionbarSherlock 一起使用的下拉导航。这是它的样子:
我想知道的是我是否可以将共享小部件放在同一个操作栏上的下拉列表旁边?如果是这样,我该怎么做?它是我必须添加的布局 xml 的一部分吗?或者在哪里/需要指定什么?
这是我的 values/arrays.xml 文件
<resources>
<string-array name="locations">
<item>Home</item>
<item>Learn</item>
<item>Services</item>
<item>Next Steps</item>
</string-array>
</resources>
这就是我开始活动的方式:
private TextView mSelected;
private String[] mLocations;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setTheme(R.style.Theme_Sherlock_Light);
但是当我尝试同时添加共享和列表导航时。它不会呈现其中一个。这是我尝试做的事情:
Context context = getSupportActionBar().getThemedContext();
ArrayAdapter<CharSequence> list = ArrayAdapter.createFromResource(
context, R.array.locations, R.layout.sherlock_spinner_item);
list.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item);
getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
getSupportActionBar().setListNavigationCallbacks(list, this);
谢谢,亚历克斯
运行时错误:
java.lang.ClassCastException: android.widget.ShareActionProvider cannot be cast to com.actionbarsherlock.view.ActionProvider
at com.actionbarsherlock.view.MenuInflater$MenuState.readItem(MenuInflater.java:389)
at com.actionbarsherlock.view.MenuInflater.parseMenu(MenuInflater.java:162)
at com.actionbarsherlock.view.MenuInflater.inflate(MenuInflater.java:112)
at com.marketing.MainActivity.onCreateOptionsMenu(MainActivity.java:880)
at com.actionbarsherlock.app.SherlockActivity.onCreatePanelMenu(SherlockActivity.java:184)
at com.actionbarsherlock.ActionBarSherlock.callbackCreateOptionsMenu(ActionBarSherlock.java:559)
at com.actionbarsherlock.internal.ActionBarSherlockNative.dispatchCreateOptionsMenu(ActionBarSherlockNative.java:65)
at com.actionbarsherlock.app.SherlockActivity.onCreateOptionsMenu(SherlockActivity.java:149)
at android.app.Activity.onCreatePanelMenu(Activity.java:2444)
at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:388)
at com.android.internal.policy.impl.PhoneWindow.invalidatePanelMenu(PhoneWindow.java:739)
at com.android.internal.policy.impl.PhoneWindow$1.run(PhoneWindow.java:2833)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)