简体   繁体   English

设置自定义操作栏视图后如何删除默认的android操作栏

[英]How to remove default android action bar after setting custom action bar view

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大家好,我有一个问题,我正在尝试从左到右移动操作栏应用程序图标、标题、菜单或...,我正在使用 SherlockActionBar 和 setCustomView 查看代码我的活动

    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.一切正常,但我有一个问题,当我的应用程序启动时,原始(默认)android 操作栏将加载 2-3 秒,然后我的自定义操作栏将显示。 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:编辑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 private void BiftorSetUpActionBar() { // TODO 自动生成的方法存根

//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.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 :-(但又一无所有:-(

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM