0

I create a custom view for my ActionBar but but it doesn't fill entire actionbar! This is the result: enter image description here

This is my actionbar layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/actionbar_background">
<TextView
    android:text="SOOPAC"
    android:textAppearance="?android:attr/textAppearanceInverse"
    android:layout_alignParentLeft="true"
    android:layout_height="match_parent"
    android:layout_width="wrap_content"
    android:gravity="center_vertical"
    android:paddingLeft="15dp"/>
<LinearLayout
    android:layout_width="35dp"
    android:layout_height="match_parent"
    android:weightSum="4"
    android:orientation="vertical"
    android:layout_alignParentRight="true">
    <Space
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.8"/>
    <View 
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.2"
        android:background="@android:color/white"/>
     <Space
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.8"/>
    <View 
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.2"
        android:background="@android:color/white"/>
     <Space
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.8"/>
    <View 
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.2"
        android:background="@android:color/white"/>
</LinearLayout>

</RelativeLayout>

this is my Activity Class:

    import android.support.v7.app.ActionBarActivity;
    import android.view.View;
    public class ActivityMain extends ActionBarActivity {
        ViewPager viewPager;
        @Override
        protected void onCreate(Bundle arg0) {
            // TODO Auto-generated method stub
            super.onCreate(arg0);
            setContentView(R.layout.activity_main);
            ActionBar actionBar = getSupportActionBar();
            actionBar.setDisplayShowHomeEnabled(false);
            actionBar.setDisplayShowTitleEnabled(false);
            actionBar.setCustomView(R.layout.actionbar_layout);
            actionBar.setDisplayShowCustomEnabled(true);
            actionBar.setDisplayHomeAsUpEnabled(false);
            actionBar.setHomeButtonEnabled(false);
            actionBar.setStackedBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.actionbar_tabs_background)));
            actionBar.setIcon(new ColorDrawable(getResources().getColor(android.R.color.transparent)));
            View homeIcon = findViewById(android.R.id.home);
            // Hides the View (and so the icon)
            if (homeIcon != null)
                ((View) homeIcon.getParent()).setVisibility(View.GONE);

            overridePendingTransition(0, 0);
        }
    }

And this is my activity View:

<android.support.v4.widget.DrawerLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    <!-- The main content view -->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"></LinearLayout>
    <!-- The navigation drawer -->
    <ListView
        android:id="@+id/listView_right_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="right"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp"
        android:background="@color/navigation_drawer_background"/>
</android.support.v4.widget.DrawerLayout>

I disabled everything in actionbar but it doesn't disappear. Edited And I set a LayoutParams with Math_Parent width and height... still have same problem

Saman Salehi
  • 1,995
  • 1
  • 22
  • 36

2 Answers2

0

try this in your actionbar

LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.MATCH_PARENT);
actionBar.setCustomView(R.layout.actionbar_layout,lp);
Akash
  • 961
  • 6
  • 15
0

First you have to check this:

styles.xml file:

<resources>

<!-- Base application theme. -->
<style name="CustomActionBarTheme" parent="Theme.AppCompat.Light">
    <!-- Customize your theme here. -->
    <item name="actionBarStyle">@style/MyActionBar</item>
</style>

<!-- ActionBar styles -->
<style name="MyActionBar" parent="Widget.AppCompat.ActionBar">
    <item name="android:windowBackground">@color/sapient_heat</item>
    <item name="background">@color/red</item>
</style>

This is not a perfect solution but there is a chance to solve.

Charuක
  • 12,953
  • 5
  • 50
  • 88
Andriya
  • 241
  • 2
  • 14