I got compilations errors in the activity class that says " edit_password ID not found" as well as the other IDs in the same .axml file. Does anyone know why?
<android.support.design.widget.TextInputLayout
android:layout_marginTop="5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/basic_button_background"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
>
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
app:passwordToggleEnabled="true"
android:id="#+id/edit_password"
android:textSize="#dimen/margin_padding_size_medium"
android:privateImeOptions="#string/abc_action_mode_done"
/>
</android.support.design.widget.TextInputLayout>
Save your .axml file ,clean and rebuild your project. It should then regenerate the Resources.designer.cs file which should include your Id definition.
I found the answer :)
You are right. I have forgotten to add this link you have mentioned:
xmlns:app="http://schemas.android.com/apk/res-auto"
but in addition to it, I had to use android:inputType="textPassword" so the toggle work
Thanks a lot for inspirations :)
Related
I'm new to android mobile development and java. And wonder if anybody can help me with my issue.
Now, I'm making XML file of my android app and want it to have something like displayed below.
Can it be made in XML file without deep knowledge of java? I just want to have fixed text in my EditText attribute. Using LinearLayout to my first app. I appreciate any kind of help.
Using API 28 for testing.
Yes, there is a default layout TextInputLayout and TextInputEditText.
Here's documentation:
https://developer.android.com/reference/android/support/design/widget/TextInputLayout
https://material.io/develop/android/components/text-input-layout/
This is called TextInputLayout.Read here. Demo example here
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:hintEnabled="true">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Username" />
</android.support.design.widget.TextInputLayout>
You are looking for the TextInputLayout component:
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Username"
app:boxBackgroundColor="#color/white"
app:boxStrokeColor="#color/text_input_layout_stroke_color"
app:counterMaxLength="15"
app:counterEnabled="true"
>
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</com.google.android.material.textfield.TextInputLayout>
Rendering Problems Couldn't resolve resource #id/search_edit_frame
This is the rendering error I'm getting in my xml file. I think it has something to do with my support.v7.SearchView below is my xml:
<RelativeLayout
android:id="#+id/layout_ricerca"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#drawable/search_border_backgroud"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_marginTop="20dp">
<android.support.v7.widget.SearchView
android:id="#+id/testo_ricerca"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:queryHint="#string/search_hint"
android:textSize="25sp"
android:layout_marginStart="5dp"
android:iconifiedByDefault="false"/>
<ImageButton
android:id="#+id/tasto_ricerca"
android:background="#color/trans"
android:layout_marginTop="2dp"
android:layout_width="45dp"
android:layout_height="match_parent"
android:layout_marginEnd="3dp"
android:scaleType="centerInside"
android:layout_alignParentEnd="true"
android:src="#drawable/tasto_ricerca"/>
</RelativeLayout>
When I change the <android.support.v7.widget.SearchView to <SearchView the error disappears, but that's not a good solution for me because I would have to change all my java code to work with the SearchView instead of the android.support.v7.widget.SearchView.
Does anyone know how to fix this problem ? why does it happen? I don't think there is anything wrong with my xml.
Edit:
Added screenshot of the error
To resolve this issue, provide an
android:id="#+id/search_edit_frame"
attribute to a parent view such as
android.support.design.widget.AppBarLayout
or any ViewGroup that is parent to your SearchView.
For example:
<android.support.design.widget.AppBarLayout
android:id="#+id/search_edit_frame"
android:layout_width="match_parent"
android:layout_height="#dimen/my_app_bar_height">
<android.support.v7.widget.SearchView
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.AppBarLayout />
When you have lot of cache memory data are store in Android Studio that time this type of error is coming..
There are many way to solve it.
Quickest way to do that is File → Invalidate caches / Restart...
→ Just Restart.
Right click on project and Synchronize ...Project
click on Build menu --> select Clean Project and then Rebuild
it.
use this code
<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" />
android:id="#+id/search_edit_frame"
add above line to parent layout that did the trick for me
Here is an easy one solution.
There is no need of invalidating cache Or restarting.
Just add below line into your strings.xml file and problem will get solved.
<item name="search_edit_frame" type="id"/>
Bingo!
I have the same problem but in eclipse IDE and I solved it by
1- click on project --> clean and it solved the problem with me
I have the next problem: I use a lot the RelativeLayout, like the Android documentation is telling me to do. But, since few days, I don´t understand why, this is not working anymore:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#drawable/background"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="#+id/boton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Button" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/boton"
android:layout_centerHorizontal="true"
android:layout_marginTop="60dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000" />
</RelativeLayout>
This is my layout, very simple. So, according to this one, the textView should be BELOW the button, but, instead, it appears OVER the button!
.
Сan anyone explain me what happens?
EDIT: The problem is not when I try to run it on a device, the problem comes when I see it on the graphical layout of the ADT Plugin for Eclipse...
I try this code it's working properly.
If your side not working properly Try to Clean build your project and then Run.
If still having problem then Try this
android:layout_below="#+id/boton"
remove above line with this
android:layout_below="#id/boton"
Because "+" create new reference to R.java file
This may be the issue.
try by removing the below line from your code
android:layout_marginTop="60dp"
Take the '+' sign out of the TextView's layout_below attribute. The '+' tells it to deine a new id. Without the '+' it should refer to the existing one.
I think your issue is the drawable for the background, since I am not seeing an image in your preview.
Having this issue is giving you a build error so the preview doesn't show the layout in its current state (it reverts to the last sucessful build). Either remove that line and save to see the preview or check to make sure that you have an image in your drawables folder titled "background"
Try this, without the drawable to check if it is working for you:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="#+id/boton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Button" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/boton"
android:layout_centerHorizontal="true"
android:layout_marginTop="60dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000" />
</RelativeLayout>
I am trying to run it, and now, I know what´s the problem.
When running the app in a terminal, it is working properly, the problems comes when I try to see it on the graphical layout on the ADT plugin on Eclipse! Anyone with the same problem??
Add </RelativeLayout> at the end of your relative layout to close it.
It seems to be the most weird thing that I've ever come across.
Here is a layout:
<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" >
<EditText
android:id="#+id/GuessAppEditText"
android:lines="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center_horizontal"
android:inputType="textCapWords"
android:hint="#string/Hint" />
</RelativeLayout>
The hint of EditText is not shown.
If I remove either android:gravity="center_horizontal" or android:inputType="textCapWords", hint becomes visible.
I have absolutely no idea what has gravity and textCapWords to do with hint. Is it another Android bug or am I doing something wrong? In the former case, what would be a workaround? I want my text to be center-aligned and capitalized and hint to be shown. Or I want too much from poor Android?
Just add a single line and it will work, i.e android:ellipsize="start"
<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" >
<EditText
android:id="#+id/GuessAppEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:ellipsize="start"
android:gravity="center_horizontal"
android:hint="hint"
android:inputType="textCapWords"
android:lines="1" />
</RelativeLayout>
Likely that the original accept answer is no longer valid for latest android version, by setting up the hint color will make the hint display:
android:textColorHint="#android:color/darker_gray"
Hope this helps others, tested with Android 5+
it's 2021 and this still seems to be an issue, so for anyone running trying to use an EditText and not seeing the hint in the designer you can add tools:background="#android:color/transparent" or assign any color to the background and the hint will appear.
It appears to be a bug, as noted here. Seems like a few people in that thread have posted work around's or resolutions you could try. Have you tried to remove the hint and set it programmatically, to see if that is a workaround?
Declare this before onCreate()
EditText guessAppEt;
And this in onCreate()
guessAppEt = (EditText)findViewById(R.id.GuessAppEditText);
guessAppEt.setHint("Your hint here");
Tested with Android 1.6(4) and 2.3.3(10).
I've made a minimalistic test application to demonstrate this, all it does is load the xml with:
setContentView(R.layout.main);
and the xml is:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/hello" />
<EditText
android:id="#+id/editText1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="none"
android:ems="10" >
</EditText>
The problem:
when setting inputType="none" the actual input type during execution becomes textMultiLine(0x00020001), I've checked it with a debugger.
On the other hand if I use inputType="text" it works as expected.
Is this a bug in Android?
I had the same problem: defining the input type via xml did not work.
Then, to fix it, I set the input type programatically:
#Override
public void onActivityCreated(#Nullable Bundle savedInstanceState)
{
...
editText1= (EditText) super.getActivity().findViewById(R.id.editText1);
editText1.setInputType(InputType.TYPE_NULL); // none...
...
}
That works for me.
Setting InputType="none" xml doesn't work, but if you're using databinding then you can use the binding syntax to set Input type.
import the type..
<data>
<import type="android.text.InputType" />
</data>
then bind the value
<EditText
android:id="#+id/edit_text"
android:inputType="#{InputType.TYPE_NULL}" />
Use android:editable="false". Even though it's deprecated, it works when inputType doesn't.
From what I can tell this is a bug in the android code. see this for refrence - How to make EditText not editable through XML in Android?
GalDude33 suggests-
android:clickable="false"
android:cursorVisible="false"
android:focusable="false"
android:focusableInTouchMode="false"
Use this
textView.setKeyListener(null);
Setting the .xml like this works, however, I had to add another line because the cursor was visible.
android:focusable="false"
android:cursorVisible="false"
It's strange that even after 2 years this "bug" is present, and the depreciated method works better than the suggested one.
Using this works as well, but you have to edit the background color in that case, unless you want the color different.
android:enabled="false"
The following code works:
Use android:enabled="false"
This is a working example:-
<AutoCompleteTextView
android:id="#+id/autoComplete"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:inputType="none"
android:enabled="false"
android:padding="15dp" />