Android Studio, DrawerLayout makes design view go blank - android

I am new to Android development so excuse me if I ask some dumb questions but I really can't figure out why whenever I switch from a relative layout or linear to a DrawerLayout my design view goes blank and only said "android....DrawerLayout".i loose all of the buttons textfields all of it goes away! I added all of the dependencies necessary to use it. All I need this drawer layout is to add a navigation view to my main screen. I have tried the but it still nothing shows in the design view so I can't really lay things out properly without seeing how it is going to look! Any help will be really appreciated!
enter image description here
<?xml version="1.0" encoding="utf-8"?>
<!-- Use DrawerLayout as root container for activity -->
<android.support.v4.widget.DrawerLayout 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:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:layout_height="match_parent">
<!-- Layout to contain contents of main body of screen (drawer will slide over this) -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:id="#+id/cardView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#CC809fff"
android:padding="10dp">
<ImageView
android:id="#+id/weatherView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:clickable="false"
android:contextClickable="true"
android:padding="10dp"
android:src="#drawable/weather" />
<View
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#color/cardview_dark_background"
android:padding="11dp"
android:visibility="visible" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="0dp"
android:text="Weather"
android:textColor="#android:color/white"
android:textSize="20dp"
android:textStyle="bold" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/cardView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#CC809fff"
android:padding="10dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:src="#drawable/news" />
<View
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:outlineAmbientShadowColor="#ff3300
"
android:visibility="visible">
</View>
<TextView
android:id="#+id/textview5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="0dp"
android:text="News"
android:textColor="#ffffff"
android:textSize="20dp"
android:textStyle="bold" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/cardView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#CC000000"
android:padding="5dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dp"
android:src="#drawable/events_icon" />
<View
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</View>
<TextView
android:id="#+id/eventsTextfield"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="10dp"
android:text="Events"
android:textColor="#color/cardview_light_background"
android:textSize="20dp"
android:textStyle="bold" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/cardView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#CC000000"
android:padding="5dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:src="#drawable/trending_icon" />
<View
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</View>
<TextView
android:id="#+id/secondview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="10dp"
android:text="Hottest"
android:textColor="#color/cardview_light_background"
android:textSize="20dp"
android:textStyle="bold" />
</android.support.v7.widget.CardView>
</LinearLayout>
<!-- Container for contents of drawer - use NavigationView to make configuration easier -->
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:menu="#menu/drawer_view" />
</android.support.v4.widget.DrawerLayout>
MY DEPENDENCIES ARE THE FOLLOWING:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
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'
implementation 'com.android.support:support-v4:28.0.0'
}
--------- BUILD.GRADLE:PROJECT---------
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

Most times this is usually because of Android studio cache issues. You can try to invalidate and restart your Android Studio by going to:
File->Invalide Caches / Restart.
Once you have added all dependencies, this should solve your problem.
I hope this helps.

If you want to use CardView you must include its dependency
Add this dependency
implementation 'com.android.support:cardview-v7:28.0.0'

Related

Recycleview of cardview is not working.How can I fix it?

I am a beginner trying to learn android developement.I try to make a recyclerview using below cardview.But when I try to run It's not working.So,how can I fix it?
The cardview code below:
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView 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"
app:cardCornerRadius="10dp"
android:id="#+id/list_layout"
android:background="#color/white"
android:layout_marginBottom="10dp"
>
<LinearLayout
android:layout_width="2000dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/ratio_button"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Do the work"
android:textSize="20sp"
android:id="#+id/task"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/delete"
android:backgroundTint="#color/red"
android:text="Delete"
android:visibility="invisible"
/>
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
implementation 'com.android.support:cardview-v7:28.0.0'
After that, Let's try this:
androidx.cardview.widget.CardView
your question is not clear! but after trying your XML file, I believe you're missing material dependencies in your app level Gradle file
implementation 'com.google.android.material:material:1.2.1'
MaterialCardView is part of this library and you should include it in your app's dependencies before using it.

android.support.v7.widget.AppCompatTextview Failed to instataniate

i am having problem, failed to instantiate one or more classes.Following classes cannot be instantiate .
android.support.v7.widget.AppCompatTextview
There it is my xml 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="wrap_content"
android:layout_marginTop="16dp"
android:orientation="horizontal">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/iv_comment_owner_display"
android:layout_width="20dp"
android:layout_height="20dp"
android:src="#drawable/facebook" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/tv_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Username"
android:textColor="#android:color/black"
android:textStyle="bold" />
<TextView
android:id="#+id/tv_comment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:text=""
android:textColor="#android:color/black" />
</LinearLayout>
</LinearLayout>
AppCompatTextView was added in appcompat-v7:22.1.0
Please check you appcompat version. You have to update your gradle file with this.
clean/Rebuild project from Android Studio,it might help.
If it doesn't try to invalidate caches and restart android studio.
If you have not done,
Try adding the dependencies in your build.gradle(Module:App)
please check the version according to your app
dependencies {
compile 'com.android.support:design:25.3.1'
}
Try putting this code in your layout
<android.support.v7.widget.AppCompatTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hello world"
android:textSize="18dp"
/>
because i see no AppCompatTextView in your layout.

ConstraintLayout's blueprint does not match the final design

As I have updated to Android Studio 2.2, I tried new ConstraintLayout to create a simple Activity. Surprisingly, alpha 8 (currently the most up-to-date) is really buggy, causing multiple resets in the blueprint stage.
The main problem is that all items that I have added through Blueprint are not constrained in the Design tab:
Design and Blueprint
The dependencies:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
//testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:design:24.2.1'
compile 'com.google.android.gms:play-services-appindexing:9.4.0'
compile 'org.apache.openejb:openejb-telnet:3.1.4'
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha8'
}
I do remember unchecking or checking some checkmark when creating new Empty Activity. Does it have to do with that?
Activity class extends Activity.
Please help me get rid of bugs of new layout constructor.
XML:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/activity_telnet"
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="xx.xxx.xxxx.TelnetActivity">
<TextView
android:text="IP:"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tv_IP"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"/>
<EditText
android:layout_width="180dp"
android:layout_height="16dp"
android:inputType="text|textPersonName"
android:ems="10"
android:id="#+id/et_IP"
android:layout_marginStart="80dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toRightOf="#+id/tv_IP" android:layout_marginLeft="80dp"
/>
<TextView
android:text="Port:"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tv_port"
app:layout_constraintLeft_toLeftOf="#+id/tv_IP"
android:layout_marginTop="16dp" app:layout_constraintTop_toBottomOf="#+id/tv_IP"/>
<EditText
android:layout_width="180dp"
android:layout_height="16dp"
android:inputType="number"
android:ems="10"
android:id="#+id/et_port"
app:layout_constraintBottom_toBottomOf="#+id/tv_port"
app:layout_constraintLeft_toLeftOf="#+id/et_IP"
/>
<Button
android:text="Connect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/btn_connect"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginTop="16dp" app:layout_constraintTop_toBottomOf="#+id/et_port"
app:layout_constraintLeft_toLeftOf="parent"
tools:layout_constraintRight_creator="1" tools:layout_constraintLeft_creator="1"
android:onClick="connect (TelnetActivity)"/>
<TextView
android:text="Status:"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView3"
android:layout_marginTop="16dp" app:layout_constraintTop_toBottomOf="#+id/btn_connect"
app:layout_constraintLeft_toLeftOf="parent"/>
<TextView
android:text="Disconnected"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tv_status"
app:layout_constraintTop_toTopOf="#+id/textView3"
app:layout_constraintLeft_toLeftOf="#+id/et_port"/>
<TextView
android:text="Send msg:"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView4"
android:layout_marginTop="16dp" app:layout_constraintTop_toBottomOf="#+id/textView3"
app:layout_constraintLeft_toLeftOf="#+id/textView3"/>
<EditText
android:layout_height="16dp"
android:ems="10"
android:id="#+id/et_sendMsg"
android:layout_width="180dp" android:inputType="text"
app:layout_constraintBottom_toBottomOf="#+id/textView4"
app:layout_constraintRight_toRightOf="#+id/et_port"/>
<TextView
android:text="Response:"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView5"
android:layout_marginTop="16dp" app:layout_constraintTop_toBottomOf="#+id/textView4"
app:layout_constraintLeft_toLeftOf="parent"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tv_response"
app:layout_constraintBottom_toBottomOf="#+id/textView5"
app:layout_constraintLeft_toLeftOf="#+id/tv_status"
app:layout_constraintTop_toTopOf="#+id/textView5"/>
<Button
android:text="OK"
android:layout_width="88dp"
android:layout_height="48dp"
android:id="#+id/btn_sendMsg"
app:layout_constraintBottom_toBottomOf="#+id/et_sendMsg"
app:layout_constraintTop_toTopOf="#+id/et_sendMsg"
android:layout_marginBottom="16dp"
android:layout_marginStart="24dp"
app:layout_constraintLeft_toRightOf="#+id/et_port" android:layout_marginLeft="24dp"
app:layout_constraintVertical_bias="0.44" android:onClick="sendMsg (TelnetActivity)"/>
</android.support.constraint.ConstraintLayout>
PS: Restarting Android Studio helped with getting all the elements on the right places, until I moved any of them. After that - everything collapses again.
If you updated from alpha7 to alpha8 (which is probably the case if you downloaded Android Studio 2.2), you may need to rebuild your project and/or do File->Invalidate Caches in Studio -- though restarting Studio should have been enough. Tell me if that works for you.
Also; on which environment are you running? (Windows, Mac, Linux, which JVM...)

Using external library: No resource identifier found for attribute

I am using BetterSpinner in my app.
When I add the xml of the BetterSpinner to my app I get the following issue:
Namespace 'app' is not bound
I have found a solution here and added the following line to my xml layout:
xmlns:app="http://schemas.android.com/apk/res-auto"
Now there is no parsing issue anymore.
But when I try to run the app I get a compile error:
Error:(32) No resource identifier found for attribute 'met_floatingLabel' in package 'com.example.jublikon'
I have added the dependency like that:
compile ('com.weiwangcn.betterspinner:library-material:1.1.0') {
exclude group: 'com.android.support', module: 'appcompat-v7'
exclude group: 'com.rengwuxian.materialedittext', module: 'library'
}
Why does Android Studio not find the resources of a completely included library by gradle?
My complete xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="10"
android:background="#color/colorPrimary"
android:id="#+id/main">
<TextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="center"
android:gravity="center"
android:paddingLeft="32dp"
android:layout_weight="3"
android:textStyle="bold"
android:textColor="#android:color/white"
android:paddingRight="32dp"
android:textSize="28sp"
android:text="TITLE"
android:id="#+id/title"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:gravity="center"
android:layout_weight="5">
<com.weiwangcn.betterspinner.library.material.MaterialBetterSpinner
android:id="#+id/spinner2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="MaterialBetterSpinner"
app:met_floatingLabel="normal" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="3"
android:layout_gravity="center"
android:gravity="center"
android:textColor="#android:color/white"
android:paddingLeft="64dp"
android:paddingRight="64dp"
android:textSize="16sp"
android:text="description"
android:id="#+id/description" />
<TextView
android:layout_width="fill_parent"
android:layout_height="64dp" />
</LinearLayout>
According to issue #23 on BetterSpinner Github page:
https://github.com/Lesilva/BetterSpinner/issues/23
You need to have in your dependencies MaterialEditText dependencies.
Did you exclude it like guy in above post?

Android Percent Support Library Blank Screen on Actual Device

I tried using the Percent Support Library as detailed here and here. It works nicely in the Android Studio designer, but when I try to install my app into my phone, nothing is showing but an empty screen. What might the problem be?
Edit:
I've added the following lines in my gradle file dependencies.
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.android.support:support-v4:23.0.0'
compile 'com.android.support:design:23.0.0'
compile 'com.android.support:percent:23.0.0'
And here is my fragment layout:
<RelativeLayout 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="org.atpms.fairfare.ReportFragment"
android:id="#+id/fragment_report" >
<ProgressBar android:id="#+id/report_progress" style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content" android:layout_height="match_parent"
android:layout_marginBottom="8dp" android:visibility="gone"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
<RelativeLayout
android:id="#+id/report_form"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/reportButton"
android:gravity="center">
<ImageView
android:id="#+id/report_background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:src="#drawable/report"
android:adjustViewBounds="true" />
<android.support.percent.PercentRelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignTop="#+id/report_background"
android:layout_alignBottom="#+id/report_background"
android:layout_alignLeft="#+id/report_background"
android:layout_alignStart="#+id/report_background"
android:layout_alignRight="#+id/report_background"
android:layout_alignEnd="#+id/report_background">
<EditText
android:id="#+id/plateNumberField"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_widthPercent="58%"
app:layout_heightPercent="14%"
app:layout_marginTopPercent="20%"
app:layout_marginLeftPercent="36%"
android:textColor="#color/plate_number"
android:background="#null"
android:gravity="center"
android:textSize="24sp"
tools:ignore="TextFields"/>
<ImageView
android:id="#+id/meterPictureButton"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_widthPercent="12%"
app:layout_heightPercent="15.5%"
app:layout_marginTopPercent="38%"
app:layout_marginLeftPercent="84%"
android:src="#drawable/camera" />
<ImageView
android:id="#+id/meterPicture"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_widthPercent="97.2%"
app:layout_heightPercent="42%"
app:layout_marginTopPercent="55.8%"
app:layout_marginLeftPercent="1.6%"
android:scaleType="fitXY"
tools:ignore="ContentDescription" />
</android.support.percent.PercentRelativeLayout>
</RelativeLayout>
<Button
android:id="#+id/reportButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/report"
android:layout_alignParentBottom="true"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:background="#drawable/report_button"
android:textSize="20sp"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:textColor="#color/button_text"
android:textAllCaps="false"
android:gravity="center"
tools:ignore="UnusedAttribute" />
</RelativeLayout>
</RelativeLayout>
Update:
Ok, I've inflated the exact same layout from an Activity using setContentView, and it works fine. It seems that the problem only arises when I try to use the PercentRelativeLayout in a Fragment layout. It appears that LayoutInflater isn't correctly inflating a layout with PercentRelativeLayout elements, but I'm still unsure and continuing to investigate.
It's not a very nice solution, but I solved this problem by just getting rid of the fragment, and making it a full-blown activity.

Categories

Resources