2

I am having problems making my toolbar look like a toolbar not just a random rectangle near the top of my screen. Here is a screenshot of what it looks like currently, enter image description here

The toolbar does not seem to fit the screen or even look like a toolbar.

My code is

MainActivity.java: public class MainActivity extends AppCompatActivity {
                      ...
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
                      ...

and in activity_main.xml:

    <RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:id="@+id/MainActivity"
    android:clickable="true"
    android:background="@color/BLACK"
    tools:context=".MainActivity">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:background="?attr/colorPrimary"
        android:elevation="8dp"
        android:minHeight="?attr/actionBarSize"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="OFF"
        android:id="@+id/OFF"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"
        android:textSize="150dp"
        android:textColor="#ffffff"
        android:visibility="visible"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="ON"
        android:textColor="#000000"
        android:id="@+id/ON"
        android:visibility="invisible"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"
        android:textSize="150dp" />

</RelativeLayout>

and in styles.xml

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <!--   your app branding color for the app bar -->
        <item name="colorPrimary">#3F51B5</item>
        <!--   darker variant for the status bar and contextual app bars -->
        <item name="colorPrimaryDark">#303F9F</item>
        <!--   theme UI controls like checkboxes and text fields -->
        <item name="colorAccent">#FF4081</item>
    </style>

</resources>

I really wanted the toolbar to look more like this

enter image description here

I am also not happy with the whiteness of the very top bar where battery level, wifi level etc are displayed. How should I fix this all?

Trajan
  • 1,380
  • 6
  • 20
  • 41
  • Can you show the entire activity_main.xml ? – MidasLefko Jan 18 '16 at 22:03
  • @MidasLefko I have edited my question to include the entire file – Trajan Jan 18 '16 at 22:08
  • Can you post the contents of your AndroidManifest.xml and more context of MainActivity please? – Numan1617 Jan 18 '16 at 22:39
  • Add this below – Stanojkovic Jan 18 '16 at 22:55
  • @Stanojkovic see my comment on your answer – Trajan Jan 18 '16 at 23:04
  • check this link: http://stackoverflow.com/questions/19799097/overlay-action-bar-with-a-translucent-status-bar – Stanojkovic Jan 18 '16 at 23:10

3 Answers3

2

Get rid of the right and left padding in your root RelativeLayout

MidasLefko
  • 4,499
  • 1
  • 31
  • 44
1

Padding on parent RelativeLayout is affecting your toolbar, you should remove

android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"

or change the value to

android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="0dp"
android:paddingBottom="0dp"

I hope it helps.

Gueorgui Obregon
  • 5,077
  • 3
  • 33
  • 57
1

Remove all paddings from your main.xml file. Add this to your styles.xml

<style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
 </style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"/>
Stanojkovic
  • 1,612
  • 1
  • 17
  • 24