Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio 3.1.3, design view is always empty

Tags:

I'm new to android development and I have this problem with my Android Studio 3.1.3 demo project or any project that I create.

Even though that I can drag and drop different controls on my design view (ConstraintLayout) but nothing shows on the design view, it shows for a split sec and then it disappears.

I can see all the elements which I drag and drop in activity_main.xml Text tab, Component Tree and even in run mode, but not in design tab, nothing shows in design view and it is always blank not even hello world shows on it.

I tried Invalidate Cache Restart, Restarting my PC, changing Zoom - In and out, Inferring constraints, but no luck. Controls

I can't do much unless I see things in design view.

Empty Design View:

Empty Design View

Run mode view

Run mode view

activity_main.xml

<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     tools:context=".MainActivity">      <Button         android:id="@+id/button2"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="Button" />      <Button         android:id="@+id/button4"         android:layout_width="wrap_content"         android:layout_height="0dp"         android:text="Button" />      <android.support.constraint.Guideline         android:id="@+id/guideline"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:orientation="vertical"         app:layout_constraintGuide_begin="20dp" />      <CheckBox         android:id="@+id/checkBox"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="CheckBox"         tools:layout_editor_absoluteX="154dp"         tools:layout_editor_absoluteY="181dp" />  </android.support.constraint.ConstraintLayout> 

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"     package="com.example.libra.myapplication">      <application         android:allowBackup="true"         android:icon="@mipmap/ic_launcher"         android:label="@string/app_name"         android:roundIcon="@mipmap/ic_launcher_round"         android:supportsRtl="true"         android:theme="@style/AppTheme">         <activity android:name=".MainActivity">             <intent-filter>                 <action android:name="android.intent.action.MAIN" />                  <category android:name="android.intent.category.LAUNCHER" />             </intent-filter>         </activity>     </application>  </manifest> 

build.gradle

apply plugin: 'com.android.application'  android {     compileSdkVersion 28     defaultConfig {         applicationId "com.example.libra.myapplication"         minSdkVersion 15         targetSdkVersion 28         versionCode 1         versionName "1.0"         testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"     }     buildTypes {         release {             minifyEnabled false             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'         }     } }  dependencies {     implementation fileTree(dir: 'libs', include: ['*.jar'])     implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'     implementation 'com.android.support.constraint:constraint-layout:1.1.2'     testImplementation 'junit:junit:4.12'     androidTestImplementation 'com.android.support.test:runner:1.0.2'     androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' } 
like image 338
Adnan ILYAS Avatar asked Jun 19 '18 13:06

Adnan ILYAS


People also ask

Where is the Design tab in Android Studio?

Open an existing layout in Android Studio, and click the Design button in the top-right corner of the editor window.

What is the default layout in Android Studio?

The Constraint layout is the default layout used in Android.

What is layout editor in Android Studio?

Android Layout Editor is the workplace in Android Studio, in which we do the design part of an android app by just dragging UI elements into the editor instead of writing XML code for it. Android Studio Layout Editor enables us to build layouts by dragging components onto the screen or editing an XML layout file.

What is the use of view in Android Studio?

View or ViewGroup subclasses are used to build the GUI elements. View is a basic building block of UI (User Interface) in android. A view is a small rectangular box that responds to user inputs. Eg: EditText, Button, CheckBox, etc.


1 Answers

Ok my problem is solved!

The following classes could not be instantiated: - android.support.v7.widget.Toolbar

I changed the res/values/styles.xml file from this:

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

to this:

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

and that solved the problem

like image 162
Adnan ILYAS Avatar answered Sep 21 '22 12:09

Adnan ILYAS