In design, EditText error "Render problem" in android - android

i have error with EditText is "render problem" in design in android when i drag and drop "Plain Text" from Palette to frame design. But when i run app, app run and show normally in genymotion.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.122" />
<EditText
android:id="#+id/editTextTextPersonName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="92dp"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView" />
</androidx.constraintlayout.widget.ConstraintLayout>
thank you!

i solved this by change rendering engine (below the message Rendering problem). Sry. forgot to take a screenshot :P

Best way is to let android studio instruct you what could be possibly done a manner; efficient & standardized for developer by pressing alt+enter or following tip icon & applying the changes.

One thing you need to always remember is that "when you are using drag and drop feature in the android studio you need to extract string resources for every component
see this image of my code
In this code, the text view type is not specified in most cases like you there is an error for Hardcoded string. try to use ALT+Enter for specifically required operation on this particular component.

Related

Android Studio preview goes blank when I add <com.google.android.material.textfield.TextInputEditText>

In any Android app that I have developed, I personally prefer the com.google.android.material.textfield.TextInputEditText view, rather than the plain EditText, just as, in my opinion, it looks much nicer in any and every way possible.
The problem, though, with using com.google.android.material.textfield.TextInputEditText, the preview in Android Studio goes blank. It is difficult to design UI when you cannot preview it except by compiling, and running the actual app on the device.
Here is my fragment_world.xml file:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
tools:context=".WorldFragment">
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/textField"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Hello, world!" />
</com.google.android.material.textfield.TextInputLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
As you can see, nothing out of the ordinary is going on here. The preview showed just fine before I added the com.google.android.material.textfield.TextInputEditText view into the layout. Now, the preview goes blank. If I switch to a different tab, and switch back, I can see the outlines of each view in the layout, but it quickly reverts back to its previous, blank state.
I have attempted to create a new, clean project, with nothing in it except this layout here:
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/textField"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Hello, world!" />
</com.google.android.material.textfield.TextInputLayout>
That did not work, the same exact thing happened.

Android Studio does not show components on design view, but shows on emulator, any idea why? [duplicate]

This question already has answers here:
Android Studio does not show layout preview
(34 answers)
Closed 4 years ago.
I just started with the Build your first app tutorial from android.com but for some reason, the design view does not show anything I drag or drop to it. I've tried creating buttons, text, plaintext etc, all with no errors, however, I can only see it when I run the app. What am I missing?
Running Android studio 3.1.4 on Ubuntu 18.04.1 LTS.
This is my first time using it, and I searched for similar questions before posting and only found questions/answers that were not similar enough to my issue to be helpful. I have tried rebuilding and invalidating the cache/restart with no avail.
Here are some snaps:
Snap of studio
Snap of emulator
Last here is the 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:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="#+id/message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginStart="#dimen/activity_horizontal_margin"
android:layout_marginTop="#dimen/activity_vertical_margin"
android:text="#string/title_home"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.design.widget.BottomNavigationView
android:id="#+id/navigation"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="0dp"
android:layout_marginStart="0dp"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="#menu/navigation" />
<EditText
android:id="#+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="KoDy Abbott"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
Please let me know if you need anything else to help answer my question. Thank you in advanced, hopefully it is something simple that I am overlooking but at this point its easier for me to ask then bang my head for another few hours.....
There is no error in your project but there are some bugs in the recent update of support libraries
Change support libraries version to 28.0.0-alpha1 and it will work all
implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
implementation 'com.android.support:design:28.0.0-alpha1'
Other solutions is that you can find an image button on the up-left. Click it and you can find a option called "force to refresh layout", click it and you problem will be solved.

Created a simple button in Android Studio and nothing appears

I'm new on Android Studio and I just want to create a button who open an URL. For that, I have just created a basic activity from the software. When I try to drag and drop on the design nothing is happening.
Here it is the screenshoot
<?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"
style="#android:style/Widget.DeviceDefault.Button"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="24dp"
android:layout_marginEnd="32dp"
android:layout_marginRight="32dp"
android:textAppearance="#style/TextAppearance.AppCompat.Button"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="Test" />
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
There is a
app:layout_constraintStart_toStartOf="parent"
missing on your button. You defined it with 0dp width, so it will scale first if you define left and right constraints.
0dp width or height inside a ConstraintLayout means, that the View will take as much space as possible with the defined Constraint attributes. You missed one for the width scaling, so it will stay 0dp.
If problem persist just follow these steps:
File> Invalid cache/Restart > Invalidate and Restart
It will then surely work
Update :
I get this problems too but it works by Choosing another theme
Problem solved by #I_A_Mok with this problem: Why doesn't the layout design preview get displayed on my Android Studio?
"Change Theme in Editor from App Theme to anything with .NoActionBar (e.g. AppCompat.NoActionBar)."
and this is working! thanks a lot! :D

Elements overlapping on each other in my android studio emulator

I am new to Android Studio, when I created my app all my elements overlapped on each other. I am not sure how to edit this code. Please give me a detailed description.
Layout editor and emulator result
Code for the layout
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="schemas.android.com/apk/res/android";
xmlns:app="schemas.android.com/apk/res-auto";
xmlns:tools="schemas.android.com/tools";
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.first.anew.MainActivity">
<TextView
android:layout_width="216dp"
android:layout_height="60dp"
android:text="Hello World!"
tools:layout_editor_absoluteY="16dp"
tools:layout_editor_absoluteX="61dp" />
<Button
android:id="#+id/button"
android:layout_width="100dp"
android:layout_height="45dp"
android:text="Login"
tools:layout_editor_absoluteY="343dp"
tools:layout_editor_absoluteX="177dp" />
<TextView
android:id="#+id/textView"
android:layout_width="215dp"
android:layout_height="65dp"
android:text="username"
tools:layout_editor_absoluteY="117dp"
tools:layout_editor_absoluteX="61dp" />
<android.support.constraint.Guideline
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/guideline"
app:layout_constraintGuide_begin="20dp"
android:orientation="horizontal" />
<EditText
android:id="#+id/editText"
android:layout_width="217dp"
android:layout_height="57dp"
android:ems="10"
android:inputType="textPassword"
tools:layout_editor_absoluteY="218dp"
tools:layout_editor_absoluteX="61dp" />
</android.support.constraint.ConstraintLayout>
Your emulator screen and the layout editor are different because of tools namespace. In a few words, it is a tool that helps you to better visualise the written code. This tool also generates constraints like tools:layout_editor_absoluteY="343dp", which inform the layout editor on how it should draw the views. The problem is that this constraints will not be present in your app code, resulting in that weird behaviour when all views are overlapped (since the above mentioned constraints are not used in the app code we can deduct that there are no constraint at all).
Since you are a beginner I would recommend to start with a LinearLayout or RelativeLayout because I think that ConstraintLayout is harder to understand, use and debug.
put the whole code. if you are using Relativelayout, this will happen. change it to Linearlayout at the top i mean the bottom most element, and put orientation as vertical
see this - for me my soltion works...
add this in xml to the button etc
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.57"
then play with it in the design.
Good luck! :)
you can click the infer Constraints buttonclick on this
and run your programme again..it will solve your problem

Android studio different layout on emulator

I just started using android studio and I inserted a button and text field. In preview panel looks ok but when I run the app the layout it's different.
This is the xml code:
<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"
android:paddingBottom="16dp"
android:paddingTop="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
tools:context="com.example.alexander.myapplication.MainActivity">
<TextView
android:id="#+id/message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
tools:ignore="HardcodedText" />
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
tools:layout_editor_absoluteX="119dp"
tools:layout_editor_absoluteY="222dp"
tools:ignore="HardcodedText,MissingConstraints"
android:onClick="buttonClicked"
/>
This is how it looks like
Thank you!
Look at the lines:
tools:layout_editor_absoluteX="119dp"
tools:layout_editor_absoluteY="222dp"
What they say is that you placed the button in an absolute position BUT only in the editor preview.
The button doesn't have real placement values when the app actually running (notice the "editor" prefix in the parameters name).
You need to define actual values in the editor.
Check out this guide on the Android developers site:
Build a Responsive UI with ConstraintLayout
I just solved the problem by setting the layout to RelativeLayout.

Categories

Resources