I'm trying to use the "tools" namespace feature in Android Studio.
I'm trying to populate the ListView with dummy list items, for design purposes. The link here says the tools:listitem="#android:layout/<filename>" should do.
But for some reason, Android Studio keeps showing Layout android:<filename> does not exist. I'm trying to find a solution for it, so I don't have to run my app again and again with dummy values for testing.
I might be overlooking something very foolish, so forgive me. Here is what I have for now:
<ListView
android:id="#+id/controllerProfiles"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="20dp"
tools:listitem="#android:layout/profiles_list_item"/>
And I have a file profiles_list_item.xml under res/layout. Any suggestions or alternatives?
you should change the following line :
tools:listitem="#android:layout/profiles_list_item"
to this :
tools:listitem="#layout/profiles_list_item"
with #android you say that you want to use a layout from android resources but your layout is in your own project files.
tools:listitem doesn't work with ListViews in Android Studio 2.2. This is a known bug. I've tested this in Android Studio 2.3 beta 1 and it is fixed here.
You can also move from ListView to RecyclerView as this bug doesn't occur at RecyclerViews.
Related
I was wondering wheather when previewing the layout in Android Studio I can see all view regardless of their visibility in order to inspect all the elements in the preview without changing something in the code (just for debugging purposes).
Thanks in advance!
you can use:
android:visibility="gone"
tools:visibility="visible"
the tools namespace is there for this type of situation where it's only relevant for development.
and then just import:
xmlns:tools="http://schemas.android.com/tools"
in your root layout, if your IDE doesn't suggest it
My issue is similar to this but Android Studio doesn't tell me anything about a rendering issue or compiler/build errors(I was able to build fine).
Here is what I am seeing(this is a new project)
And the contents of content_main.xml
After reading on different rendering issue threads, I I've tried rebuilding, cleaning, invalidate caches/restart and even starting a new project to see if the layout preview was working(Still empty)
I also played around with different sdk versions(20,19) to see if the layout preview was working but all I got was this quirky issue that I don't think would cause the layout preview to not work.
Does anyone know what my problem is here? I didn't mess around with my initial Gradle files and remove any support library dependencies. Another solution I had in mind was reinstalling Android Studio but that's last resort.
Just check your sdk valid version like example.
Try putting your TextView element into an empty FrameLayout:
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/my_groups" />
</FrameLayout>
This code above should be put inside your RelativeLayout. Hope it helps.
When I do changes to a layout resource file it's not updated/reflected when the apk file is buildt and installed from Android Studio 2.0 (Preview 3b).
Example:
I had a EditText and I added a TextInputLayout like this:
<android.support.design.widget.TextInputLayout
android:id="#+id/input_layout_new_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp">
<EditText
android:id="#+id/edit_text_new_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/hint_your_new_password"
android:inputType="textPassword"
android:saveEnabled="false" />
</android.support.design.widget.TextInputLayout>
The result after updating the app is the same as before I added the TextInputLayout, just the EditText without TextInputLayout.
What I've tried:
Build/Clean Project
Build/Rebuild Project
File/Invalidate Caches / Restart..
Uninstall app first
Turn off Instant Run
I suspect this is probably a bug with the Preview 3b version of Android Studio 2.0 causing this. Any ideas? Maybe it's just a settings/configuration?
Temporary solution:
If you make a copy of the layout file and inflate it instead. Then the changes are updated in the app? But this is not ideally the best solution!
Also make sure you make the changes in the layout-v<target-api> folder if you have set specific layout for specific api level. For example layout-v23 in mine case.
This issue is typically caused by only updating the xml file in one layout folder and not the other folders containing the file's compatibility variants as well. For example, only editing the xml file in the layout system folder and not the layout-v14 folder too will cause this issue.
The fix: update the instance of the layout xml file not only in your layout folder, but the instances in all other layout folders too (layout-v14, layout v-21, etc.)
I wasn't able to reproduce this issue. I tried the same layout changes with Preview 3b and the changes showed up in the emulator fine. I simply hit the run button again.
Was this working for you in a previous version of Android Studio?
I'm new at Android testing and I'm trying to test a custom view in an android library and i'm using Android Studio.
I found here : Android: How to test a custom view? that I should use ActivityUnitTestCase and a mock activity.
I have put my xml layout inside projectname/library/src/androidTest/res/layout and my test activity know my layout R id thanks to this : Configuring res srcDirs for androidTest sourceSet.
My issues is in the layout content.
<?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">
<eu.custom.customView
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
In my case, "http://schemas.android.com/apk/res/android" display in red with an error "URI not registered" and the IDE doe's not recognize my custom view if I add it in this xml.
Is there a way to have this layout working without putting it in production code ?
Thanks
Well, in my Eclipse IDE your code looks correct (there are no red lines) may I suggest you to download the ADT-Bundle again or use Android Studio? I think your IDE is corrupted or something in your settings is wrong. Also check if you have downloaded the up-to-date SDK build tools.
I just did an update of my SDK and now eclipse is giving me all sorts of totally unwanted warnings in my xml... for example I have a RelativeLayout that doesn't have an id or a background (it's actually a transparent button) and eclipse is warning me that it's a useless element. Is there a way to turn this idiocy off?
TIA
According to the documentation at http://tools.android.com/recent/ignoringlintwarnings you do this by including the tools xmlns:
xmlns:tools="http://schemas.android.com/tools"
And then adding a tools:ignore annotation in the relevant elements:
<RelativeLayout
tools:ignore="UselessParent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="30dp"
android:layout_centerInParent="true">
This still works perfectly in 2022.
In New Update of Eclipse ADT Plugins will give you New Tool Which Name is Lint here is one SO Link for this tool and it's advantages .Click Here
Now for Disable xml Warnings that are come from Lint Android Tool ,you need to go
Window-->Preferences-->Android-->Lint Error Checking
in this Dialog you will find all Issue for Xml in android and you can make disable it ,if you want to disable.And Make sure you will not disable usefull lint warning because it's help us to find there are multiple ID assign in xml and lot more..