gpt4 book ai didi

android - ActionBarSherlock 在选项卡导航和 ActionMode 上重叠

转载 作者:行者123 更新时间:2023-11-29 01:48:52 25 4
gpt4 key购买 nike

我在使用选项卡导航和操作模式时遇到 ActionBarSherlock 的奇怪问题。

重复问题很简单,我使用演示代码生成以下示例 Activity :

import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.app.ActionBar.Tab;
import com.actionbarsherlock.view.ActionMode;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;

import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;

public class MainActivity extends SherlockFragmentActivity implements ActionBar.TabListener {
private ActionMode actionMode = null;

@Override
public void onCreate(Bundle savedInstanceState) {
setTheme(com.actionbarsherlock.R.style.Theme_Sherlock);
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
for (int i = 1; i <= 2; i++) {
ActionBar.Tab tab = getSupportActionBar().newTab();
tab.setText("Tab " + i);
tab.setTabListener(this);
getSupportActionBar().addTab(tab);
}

actionMode = startActionMode(new TestActionMode());
}

@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
}

@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
}

@Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
}


private final class TestActionMode implements ActionMode.Callback {

@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
menu.add("Add").setIcon(android.R.drawable.ic_input_add).setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
menu.add("Search").setIcon(android.R.drawable.ic_search_category_default).setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

return true;
}

@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
// TODO Auto-generated method stub
return false;
}

@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
// TODO Auto-generated method stub
return false;
}

@Override
public void onDestroyActionMode(ActionMode mode) {
// TODO Auto-generated method stub

}

}

}

它在 Android 4.0 上正常工作(在真实设备和模拟器上测试),但在 Jelly Bean 上(仅在模拟器上测试)我有以下行为。

  • 应用程序启动(纵向模式)并且运行正常;
  • 我轮换应用程序并且它正常工作;
  • 我再次旋转应用程序,现在选项卡导航和 ActionMode 重叠(http://i.stack.imgur.com/Zf1VG.png)。

有时(但很少见),一切都完美无缺,尤其是当我在 Dev 中启用所有动画时。设置(通常我禁用所有动画)。

我正在使用 ActionBarSherlock 4.4。

任何建议将不胜感激,因为我真的不明白我在哪里犯了错误。

感谢和问候。

最佳答案

我最近遇到了同样的问题。在浪费了几天之后,发现这种奇怪的行为是由 this issue 中描述的 UX 缺陷引起的。事实上,与 ABS (action bar sherlock) 无关.

最可靠的解决方法似乎是使用反射来控制应如何呈现操作栏:

/**
* On Android 3.0 and above, while using the ActionBar tabbed navigation style, the tabs sometimes appear above the action bar.
* This helper method allows you to control the 'hasEmbeddedTabs' behaviour.
* A value of true will put the tabs inside the ActionBar, a value of false will put it above or below the ActionBar.
*
* You should call this method while initialising your ActionBar tabs.
* Don't forget to also call this method during orientation changes (in the onConfigurationChanged() method).
*
* @param inActionBar
* @param inHasEmbeddedTabs
*/
public static void setHasEmbeddedTabs(Object inActionBar, final boolean inHasEmbeddedTabs)
{
// get the ActionBar class
Class<?> actionBarClass = inActionBar.getClass();

// if it is a Jelly Bean implementation (ActionBarImplJB), get the super class (ActionBarImplICS)
if ("android.support.v7.app.ActionBarImplJB".equals(actionBarClass.getName()))
{
actionBarClass = actionBarClass.getSuperclass();
}

try
{
// try to get the mActionBar field, because the current ActionBar is probably just a wrapper Class
// if this fails, no worries, this will be an instance of the native ActionBar class or from the ActionBarImplBase class
final Field actionBarField = actionBarClass.getDeclaredField("mActionBar");
actionBarField.setAccessible(true);
inActionBar = actionBarField.get(inActionBar);
actionBarClass = inActionBar.getClass();
}
catch (IllegalAccessException e) {}
catch (IllegalArgumentException e) {}
catch (NoSuchFieldException e) {}

try
{
// now call the method setHasEmbeddedTabs, this will put the tabs inside the ActionBar
// if this fails, you're on you own <img src="http://www.blogc.at/wp-includes/images/smilies/icon_wink.gif" alt=";-)" class="wp-smiley">
final Method method = actionBarClass.getDeclaredMethod("setHasEmbeddedTabs", new Class[] { Boolean.TYPE });
method.setAccessible(true);
method.invoke(inActionBar, new Object[]{ inHasEmbeddedTabs });
}
catch (NoSuchMethodException e) {}
catch (InvocationTargetException e) {}
catch (IllegalAccessException e) {}
catch (IllegalArgumentException e) {}
}

以上代码摘自this blog post .

关于android - ActionBarSherlock 在选项卡导航和 ActionMode 上重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19633642/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com