【问题标题】:Header bar and sherlock action bar overlapping标题栏和夏洛克动作栏重叠
【发布时间】:2013-11-27 03:00:46
【问题描述】:

我开发了一个应用程序,当应用程序安装在5英寸以上的高屏幕分辨率设备上(在Nexus 5上测试)时,应用程序的标题栏与Sherlock Action Bar在同一行。

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    sActionBar = getSupportActionBar();
    setContentView(R.layout.simple_tabs);
    sContext = this;

    View actionbar = LayoutInflater.from(sContext).inflate(
            R.layout.header_bar, null);
    sActionBar.setDisplayShowCustomEnabled(true);
    sActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    sActionBar.setCustomView(actionbar);


    View homeIcon = findViewById(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ? android.R.id.home
            : R.id.abs__home);

    ((View) homeIcon.getParent()).setVisibility(View.GONE);
    ((View) homeIcon).setVisibility(View.GONE);

    sActionBar.setBackgroundDrawable(getResources().getDrawable(
            R.drawable.actionbar_tabs_selector));

    if (savedInstanceState != null) {
        sActionBar.setSelectedNavigationItem(savedInstanceState
                .getInt("tab"));
    }

    displayUi();

    sActionBar.setSelectedNavigationItem(0);

}



/**
 * Handle UI
 */

public void displayUi() {

    // santosh
    View customView1 = LayoutInflater.from(sContext).inflate(
            R.layout.action_bar_tab_text, null);
    View customView2 = LayoutInflater.from(sContext).inflate(
            R.layout.action_bar_tab_text, null);
    TextView titleTV1 = (TextView) customView1
            .findViewById(R.id.action_custom_title);
    TextView titleTV2 = (TextView) customView2
            .findViewById(R.id.action_custom_title);

    sPager = (ViewPager) ((SherlockFragmentActivity) sContext)
            .findViewById(R.id.pager);

    mTabsAdapter = new TabsAdapter((SherlockFragmentActivity) sContext,
            sActionBar, sPager);

    mTabsAdapter.addTab(sActionBar.newTab().setText(CONTENT1[0]),
            CustomerStatisticsFragment.class, null);

    mTabsAdapter.addTab(sActionBar.newTab().setText(CONTENT1[1]),
            BusinessStatisticsFragment.class, null);


    ActionBar.LayoutParams layoutParams = new LayoutParams(Gravity.CENTER);
    customView1.setLayoutParams(layoutParams);
    customView2.setLayoutParams(layoutParams);

    titleTV1.setText(CONTENT1[0]);
    sActionBar.getTabAt(0).setCustomView(customView1);
    titleTV2.setText(CONTENT1[1]);
    sActionBar.getTabAt(1).setCustomView(customView2);

    final TextView headerText = (TextView) ((SherlockFragmentActivity)     sContext)
            .findViewById(R.id.txtHeader);
    headerText.setText(sContext.getString(R.string.statistics));

}

问题截图:

请建议我任何可能的解决方案。

【问题讨论】:

  • 嗨,这在分辨率较低的设备上是否正常工作? Nexus 5 使用 xxhdpi 资源,因此您的问题可能来自此。另一件事是您为什么要在 API 级别之间有所不同? ActionBarSherlock 通常允许您使用相同的代码。
  • 是的,它在较低的分辨率下工作得很好。

标签: android layout android-fragments actionbarsherlock fragment-tab-host


【解决方案1】:

我在 Nexus 4(Android 4.4 版本)中也遇到了这个问题,并像这样修复了它..

      view = inflater.inflate(R.layout.cus_actionbar_top, null);

    actionbar.setCustomView(view);
    actionbar.setDisplayShowCustomEnabled(true);
    actionbar.setDisplayShowHomeEnabled(false);
    actionbar.setHomeButtonEnabled(false);    


View homeIcon = findViewById(Build.VERSION.SDK_INT >= 
            Build.VERSION_CODES.HONEYCOMB ? android.R.id.home:   R.id.abs__home);
     ((View) homeIcon.getParent()).setVisibility(View.GONE);
     actionbar.setDisplayShowTitleEnabled(false);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多