Hana Hana - 1 year ago 80
Android Question

ToolBar always raised Android

I want to extend my application toolbar, but it does not seem to work correctly.
enter image description here

My code is this:

<RelativeLayout android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay"
>
<TextView
android:text="Remplissez le formulaire pour signaler un probléme dans votre batîment"
android:layout_width="201dp"
android:layout_height="59dp"
android:id="@+id/textView"
android:textColorLink="@color/common_google_signin_btn_text_dark_default"
android:textAlignment="center"
android:gravity="center_vertical|center_horizontal|center"
android:layout_gravity="center_vertical|center_horizontal"
android:textColor="@color/textbody"

/>
<View
android:layout_width="30dp"
android:layout_height="1dp"
android:background="#FFFFFF" />
</android.support.design.widget.AppBarLayout>


<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/allLayout"
android:elevation="20dp"

>


<LinearLayout
android:layout_width="fill_parent"
android:orientation="vertical"
android:layout_height="fill_parent"
android:id="@+id/lay"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:layout_marginTop="84dp"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:weightSum="1">



<EditText
android:id="@+id/EditTextEmail"
android:layout_height="wrap_content"
android:hint="@string/feedbackemail"
android:inputType="textEmailAddress"
android:layout_width="360dp">
</EditText>

<Spinner
android:id="@+id/nomSite"
android:layout_width="match_parent"
android:layout_height="39dp"
android:prompt="@string/nomdusite"
android:entries="@array/categories"
android:hint="Nom du site"
android:layout_marginTop="20dp" />

<Spinner
android:id="@+id/categories"
android:layout_width="match_parent"
android:layout_height="39dp"
android:prompt="@string/types"
android:entries="@array/types"
android:layout_marginTop="25dp" />

<EditText
android:layout_width="354dp"
android:layout_height="136dp"
android:inputType="text"
android:hint="Description*"
android:ems="10"
android:id="@+id/message"
android:textSize="18sp"
android:layout_marginTop="10dp" />

<Button
android:text="Ajouter une photo"
android:layout_width="316dp"
android:layout_height="wrap_content"
android:id="@+id/button2"
android:textColorLink="@android:color/holo_blue_dark"
android:drawableLeft="@android:drawable/ic_menu_camera"
android:gravity="center_vertical|center_horizontal|center"
android:layout_gravity="center_vertical|center_horizontal"
android:onClick="addPhoto"
android:layout_marginTop="15dp" />

<Button
android:text="Valider"
android:layout_width="113dp"
android:layout_height="wrap_content"
android:id="@+id/button3"
android:gravity="center_vertical|center_horizontal|center"
android:layout_gravity="center_vertical|center_horizontal"
android:onClick="sendForm"
android:layout_marginTop="10dp" />


</LinearLayout>

</RelativeLayout>




As you can see in the picture, some part of the toolbar has more elevation than the rest. How do i fix it?

Answer Source

Add this line getSupportActionBar().setElevation(0); in your onCreate() method:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_your_layout);
    getSupportActionBar().setElevation(0);
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download