设置自定义操作栏视图后如何删除默认的Android操作栏 [英] How to remove default android action bar after setting custom action bar view

查看:143
本文介绍了设置自定义操作栏视图后如何删除默认的Android操作栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我有一个问题 我正在尝试从左向右移动操作栏应用程序图标,标题,菜单或.... 我正在使用带有setCustomView的SherlockActionBar参见代码 我的活动

Hi all I have one problem I am trying to move action bar app icon,title,menu or... from left to right and I am using SherlockActionBar with setCustomView see codes my activity

    private void BiftorSetUpActionBar() {
    // TODO Auto-generated method stub
    getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); 
    View actionbarview = getLayoutInflater().inflate(R.layout.biftor_action_bar, null);

    View app_actionbar_bg =(View) actionbarview.findViewById(R.id.app_actionbar_bg);

    app_actionbar_bg.setBackgroundResource(R.drawable.list_item_bg_normal);
    BiftorApptitle=(TextView) actionbarview.findViewById(R.id.app_name);
    BiftorAppIcon=(ImageView) actionbarview.findViewById(R.id.app_icon);
    BiftorAppIcon.setClickable(true);
    BiftorAppMenu=(ImageView) actionbarview.findViewById(R.id.app_menu);
    BiftorAppIcon.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            if(!mDrawerLayout.isDrawerOpen(Gravity.RIGHT))
                mDrawerLayout.openDrawer(Gravity.RIGHT);
            else
                mDrawerLayout.closeDrawer(Gravity.RIGHT);


        }
    });

    BiftorAppMenu.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            openOptionsMenu();
        }
    });


    getSupportActionBar().setCustomView(actionbarview);
}

我的操作栏布局

    <?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="match_parent"
    android:id="@+id/app_actionbar_bg"
    android:background="@drawable/list_item_bg_normal"

     >

    <ImageView
        android:id="@+id/app_icon"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:id="@+id/app_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/app_menu"
        android:layout_centerHorizontal="true"
        android:text="Large Text"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="#ffeeeeee"
        android:textSize="20sp"
        android:textStyle="bold" />

    <ImageView
        android:id="@+id/app_menu"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/app_icon"
        android:layout_alignParentLeft="true"
        android:src="@drawable/abs__ic_menu_moreoverflow_holo_dark" />

</RelativeLayout>

一切正常,但是我有一个问题,当我的应用启动时,原始的(默认)Android操作栏将加载2-3秒,然后显示我的自定义操作栏. 我不想要,我想完全删除原始文件.

all things is OK but I have one problem,when my app launch the original (default) android action bar will load for 2-3 seconds then my custom action bar will show. I don't want it,I want remove the original completely.

观看此视频,您会明白我的意思

look at this video you will get what I am saying

此视频

我在等. 谢谢大家

修改1:

我通过在Google和此网站上进行搜索来更改了某些内容,但仍然是第一个默认操作栏,然后再加载我的自定义操作栏

I changed some things by searching on Google and this site but still first default action bar first then load my custom action bar

private void BiftorSetUpActionBar(){ //TODO自动生成的方法存根

private void BiftorSetUpActionBar() { // TODO Auto-generated method stub

//getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); 
getSupportActionBar().setDisplayShowHomeEnabled(false);
getSupportActionBar().setDisplayShowTitleEnabled(false);
View actionbarview = getLayoutInflater().inflate(R.layout.biftor_action_bar, null);
View app_actionbar_bg =(View) actionbarview.findViewById(R.id.app_actionbar_bg);
app_actionbar_bg.setBackgroundResource(R.drawable.list_item_bg_normal);

  .
  .
  .
  .Skip....
  .
  .
  .

getSupportActionBar().setCustomView(actionbarview);
getSupportActionBar().setDisplayShowCustomEnabled(true);}

并更改了style.xml

and changed the style.xml

   <style name="BiftorAppTheme" parent="Theme.Sherlock.Light.DarkActionBar">
        <item name="actionBarStyle">@style/Widget.Styled.ActionBar</item>

    </style>

    <style name="Widget.Styled.ActionBar" parent="Widget.Sherlock.Light.ActionBar.Solid.Inverse">
        <item name="background">@drawable/list_item_bg_normal</item>
        <item name="android:background">@drawable/list_item_bg_normal</item>
    </style>

但还是一无所有:-(

推荐答案

在一个片段中,您可以执行以下操作:

In a fragment you can do this:

 ActionBar actionbar =  ((MainActivity)requireActivity()).getSupportActionBar();
  actionbar.setDisplayOptions(actionbar.DISPLAY_SHOW_CUSTOM);
        actionbar.setCustomView(R.layout.app_bar_custom_layout);

这篇关于设置自定义操作栏视图后如何删除默认的Android操作栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆