Custom actionbar does not take up the entire screen width

Asked

Viewed 69 times

0

Well, I was trying to customize my Actionbar, it worked, but it turns out that it doesn’t fill the entire width of the screen, it’s as if it was superimposed on the old one, to better understand note the image below:

Emulador

This is my custom Actionbar . xml class:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:weightSum="1"
    android:layout_width="match_parent"
    android:layout_height="60dp"
    android:background="#bb0000">

    <TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="0.85"
        android:layout_gravity="center"
        android:gravity="left"
        android:paddingLeft="10dp"
        android:text="Tarefas"
        android:textSize="25dp"
        android:textColor="#fff"
        android:textStyle="bold"/>

    <Button
        android:id="@+id/btNewTask"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="0.15"
        android:text="+"
        android:textSize="50dp"
        android:textColor="#fff"
        android:background="@android:color/transparent"/>

</LinearLayout>

And this is my code that goes to custom Actionbar:

public class CustomActionBar {

    static Button btNewTask;

    public static void setCustomActionBarView(ActionBar actionBar, LinearLayout layout, final Context context) {
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
        actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);

        ActionBar.LayoutParams params = new ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT,
                ActionBar.LayoutParams.MATCH_PARENT, Gravity.LEFT);

        btNewTask = (Button) layout.findViewById(R.id.btNewTask);

        btNewTask.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(context, "TESTE", Toast.LENGTH_SHORT).show();
            }
        });

        actionBar.setCustomView(layout, params);
        actionBar.setDisplayHomeAsUpEnabled(false);
    }
}

Someone could solve this problem?

Att. Jeiferson

  • Why don’t you use a tooBar or actionBar?

  • @Fabianoaraujo but I’m using Actionbar, I edited the title for better understanding.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.