Akhil Vaid
Akhil Vaid

Reputation: 11

Why doesn't this layout work for Android Studio?

I am trying to make a simple greet friend app. in android Studio 3.0.1

my XML code for activity_main.xml is

<?xml version="1.0" encoding="utf-8"?>
<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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="hk.ust.cse.comp107x.greetfriend.MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="250dp"
        android:text="Hello World!" />
</RelativeLayout>

and my code in main activity class is

package hk.ust.cse.comp107x.greetfriend;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

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


    }
}

I still haven't completed by putting buttons and text boxes but I face a problem.

When I see the preview of my app in emulator/ Virtual Device I get a grey screen inside a phone The Screenshot with Android...ActionBar Overlay layout written.

Am I doing something wrong here?

I'm new to XML so I don't get the lingo too much... Thanks a lot.

Upvotes: 1

Views: 147

Answers (3)

Shivani Bulsara
Shivani Bulsara

Reputation: 1

I think it is because you have not sdk downloaded for the platform your preview is using.Change platform of android preview screen. see screenshot I have sdk tools for 24 you can change it accordingly or you can download your platform tools by opening standalone sdk.

If this solution does not work then try to change theme of the activity in preview from beside of platform tool selection button.

Upvotes: 0

Matin Gdz
Matin Gdz

Reputation: 217

these codes are correct. to solve this problem, find the "values" directory, then open "styles.xml". change

 <style name="AppTheme" parent="Theme.AppCompat.*"> 

to:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

Upvotes: 0

Hai Hack
Hai Hack

Reputation: 1018

Don't worry. You can run your app normally. Change your theme style in AndroidManifest.xml as following to make the preview works

<application
        .....
        android:theme="@style/Theme.AppCompat.Light.NoActionBar">

Upvotes: 2

Related Questions