Tata Fombar
Tata Fombar

Reputation: 349

How to change the default layout(activity_main) in android studio

I want to create a login activity for my app but the default layout keeps showing up when i run my app on AVD.

i don't want any blue on my layout, all i want in the yellow part

below is my layout file

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1"
android:paddingLeft="20dp"
android:paddingTop="20dp"
android:paddingRight="20dp"
android:paddingBottom="20dp"
android:background="@android:color/holo_orange_light">


<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:text="@string/mobile_money_market"
    android:layout_weight="0.05"
    android:textAlignment="center"
    android:inputType="text"
    android:textStyle="bold" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:layout_weight="0.05"
    android:text="@string/free_advertising"
    android:textAlignment="center" />

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="textEmailAddress"
    android:ems="10"
    android:id="@+id/editText1"
    android:hint="Email..."
    android:layout_marginTop="30dp" />

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="textPassword"
    android:ems="10"
    android:id="@+id/editText2"
    android:hint="Password..."
    android:layout_marginTop="20dp" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:id="@+id/item">

    <Button
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="@string/sign_in"
        android:id="@+id/sign_in_button"
        android:layout_weight="1" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/sign_up"
        android:id="@+id/sign_up_button"
        android:background="@color/errorColor" />

</LinearLayout>
</LinearLayout>

I want to know how to remove the blue portion from my activity. I don't want the name Mobile Money Market to appear twice as show in the picture above.

I want to remove the default android Header(The portion in Blue) from the layout.

my layout as it appears on my AVD

I need help please. Can someone advice me on what to do or what not to do. Thanks in advance

Upvotes: 2

Views: 4130

Answers (4)

Dileep Patel
Dileep Patel

Reputation: 1988

You can try to this code..

Mainactivity.java

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_main);

  }
}        

Main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/holo_orange_light"    
android:orientation="vertical">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:background="@android:color/holo_orange_light">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:gravity="center"
        android:text="Home Activity"
        android:textSize="20sp" />
</LinearLayout>

and style.xml

  <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

Upvotes: 0

Goblin  シ
Goblin シ

Reputation: 90

You can access that BLUE BAR as per your requirement from the "Styles" resource file. You Can change colour, theme, style etc as per ur need. Go to XML files, Click:-

res -> values -> styles.

Upvotes: 0

Ravers
Ravers

Reputation: 1040

You need to hide the action bar. The simplest way to do that is to add a style in the style.xml file. Something like this:

<resources>
    <!-- No action bar theme -->
    <style name="NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/blueDark</item>
        <item name="colorPrimaryDark">@color/blueDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
</resources>

Did you notice the parent? "NoActionBar". And then in your manifest change the theme of your activity:

<activity
        android:name="your.package.name.YourActivity"
        android:label="@string/application_name"
        android:theme="@style/NoActionBar" />

Upvotes: 1

D.J
D.J

Reputation: 1559

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

Add these lines before setContentView

Upvotes: 0

Related Questions