How to remove default android action bar after setting custom action bar view

旧巷老猫 提交于 2020-03-05 15:12:13

问题


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);
}

my action bar layout

    <?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>

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

This video

I am waiting. Thanks All

edit 1:

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 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);}

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>

but again nothings :-(

来源:https://stackoverflow.com/questions/26716029/how-to-remove-default-android-action-bar-after-setting-custom-action-bar-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!