When i create new sample project with TextInputLayout , Its working good.
But in my exist project if i have added TextInputlayout , its throws runtime exception caused by java.lang.UnsupportedOperationException.
Why its happen? How to resolve this?
compile 'com.android.support:design:22.2.0'
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.TextInputLayout
android:id="#+id/til"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/textDialog"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="First Name"/>
</android.support.design.widget.TextInputLayout>
</LinearLayout>
Why it happen? how to solve this?
Compare the gradle files of your sample project to your real project. Your project might not be setup correctly to use Material Design resources.
Related
I would like to change the name of the graphics, but android studio shows an error:
"Cannot perform the refactoring. This element cannot be renamed"
On the left is a tutorial on where it works, and on the right my code
<?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">
<TextView
android:id="#+id/name_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/name"
android:textAlignment="center"
style="#style/NameStyle" />
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srcCompat="#android:drawable/btn_star_big_on"
/>
</LinearLayout>
Refactor works only in the id window:
Why doesn't it work in XML code?
This is the first project on Kubuntu 20.04 LTS.
You are trying to rename a built in drawable of the android platform while the tutorial screenshot you posted is trying to rename the id of the view
What I mean is
The resources having the #android: as prefix are the ones that are built in the android platform and thus can't be refactored or renamed and your screenshot is trying to rename like so. You can see the dialog title Rename xyz and its occurence to which indicates what element you are trying to rename
<ImageView
android:id="#+id/imageView" // This is being changed in the screenshot
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srcCompat="#android:drawable/btn_star_big_on" // You are trying to change this
when first defining id ( #+id ) in constraint part ( such as app:layout_constraintBottom_toTopOf ) i get the error "cannot resolve symbol"
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="#+id/tv2" />
<TextView
android:id="#id/tv2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</android.support.constraint.ConstraintLayout>
see the screen shot:
In gradle I have constraint layout 1.1.3 and Android studio version is 3.2.1 I recently updated it from older version:
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
app runs correctly without any error but the error is shown in android studio layout window.
Invalidating caches, rebuilding, and changing constraint layout version NONE of them helps!
In Java class R.id.tv2 works correctly and when i control+click it I can see its field in R class. editor is using another class for ids that is not same as the R class in java code?
This question was about a bug in old Android Studio and ConstraintLayout versions in current versions of Android Studio using androidx library this bug is not presented.
The plus sign + is added when defining the id (#+id/tv2) but when referencing you don't need to add the plus sign like this #id/tv2.
Instead of this
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="#+id/tv2" />
<TextView
android:id="#id/tv2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</android.support.constraint.ConstraintLayout>
use this:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="#id/tv2" />
<TextView
android:id="#+id/tv2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</android.support.constraint.ConstraintLayout>
To get it right I suggest you convert your code to Androidx.
The below code is written in Androidx
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="#id/tv2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="#+id/tv2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Screenshot
As already mentioned in the other answers, use #+id/<your_name> to declare new resources.
In my case, Android Studio complained when using the - character in names (even though the app compiled and worked either way).
This question was about a bug in old Android Studio and ConstraintLayout versions in current versions of Android Studio using androidx library this bug is not presented.
Using the new Material Design guidelines I am trying to create a textfield that is outlined.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:padding="10dp">
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:boxStrokeWidth="2dp"
app:boxStrokeColor="#color/colorPrimary"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
The result has no outline or change in appearance. Android Studio does throw a Render Problem. 'Couldn't resolve resource #string/path_password_strike_through' . I have tried to rebuild and clean the project with no luck.
Any thoughts would be great, thanks.
I had same issue, add this app:passwordToggleDrawable="#string/your_string" and an error while rendering TextInputLayout that says Couldn't resolve resource #string/path_password_strike_through is gone.
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:boxStrokeWidth="2dp"
app:boxStrokeColor="#color/colorPrimary"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
app:passwordToggleDrawable="#string/your_string">
i got error : Exception raised during rendering this$0
this is my xml :
<?xml version="1.0" encoding="utf-8"?>
ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
xmlns:tools="http://schemas.android.com/tools"
android:padding="#dimen/activity_horizontal_margin"
android:id="#+id/fairy_animation"
android:layout_width="wrap_content"
android:layout_height="match_parent">
<TextView
style="#android:style/TextAppearance.Medium"
android:id="#+id/textview_language"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/layout_container"
android:layout_alignBaseline="#+id/button_language"
android:gravity="center_horizontal"
android:text="#string/text_is_in"/>
<Spinner
tools:listitem="#android:layout/simple_spinner_item"
android:id="#+id/button_language"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/layout_container"
android:drawSelectorOnTop="true"
android:layout_toRightOf="#+id/textview_language"
android:layout_toEndOf="#+id/textview_language"/>
</RelativeLayout>
i don't understand how to fix it. please help. i'm new at this. i'm using android studio 2.0
This issue comes from this line:
tools:listitem="#android:layout/simple_spinner_item"
You can avoid it by removing it or use a different layout. (e.g. simple_list_item_1)
Looks like the same basic issue: https://code.google.com/p/android/issues/detail?id=209139
You have to
change ScrollView.....> to <ScrollView.....>
Add </SCrollView> after </RelativeLayout>
Refer xml rules to gain more knowledge.
I am having an error that says couldn't resolve #id/search_edit_frame I don't know why,
I tried the File>Invalidate Caches> Just Restart and restart android studio also tried to change the render version all of my supported api..
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
myapp="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.SearchView
android:id="#+id/svSearch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="25sp"
android:textColor="#color/textDefault"
myapp="#string/search_hint"
myapp="false" />
</LinearLayout>
I'm using Android Studio 1.2.2 and sure that it compiles android.support.v7.widget(AppCompat)
any help will be appreciated.. thanks
Use
<SearchView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/searchView"
android:iconifiedByDefault="true"
android:queryHint="Search"
android:layout_centerHorizontal="true" />
it should work
First, you can search #id/search_edit_frame in all your xml file to check where it comes from.
Second, if you are sure that there is no #id/search_edit_frame in your xml, then you can try to delete all files in your Build folder.
Try to clean your project also.