In an xml layout file, the xmlns is already defined, but I get this error at compile time: No resource identifier found for attribute. Why is that? thanks
I'm following a Facebook dev tutorial on facebook site https://developers.facebook.com/docs/getting-started/facebook-sdk-for-android/3.0/ the layout file is as follows:
<ScrollView 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"
>
<com.facebook.widget.ProfilePictureView
android:id="#+id/profilepic"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
app:preset_size="large" app:is_cropped="true"
/>
</ScrollView>
I figured it out, have to replace /res-auto with res/com.facebook.samples.profilepicture
Your layout file looks correct. check that in your 'project.properties' file, the 'android.library.reference.1' value points to the correct location.
The res-auto is feature properly supported in API level 17. It must be applied for all layouts using custom attributes. It is automatically replaced on build time, by eclipse.
Ref Updated SDK Tools and ADT revision 17
Related
I have seen EditText that has a hint and when user taps on it the hint moves up reducing the font size and making the field editable by the user. When the user moves to another EditText leaving it blank the hint appears back in full size.
What is it and how can I add it in my activity on Android Studio using XML?
I am on Android Studio using Kotlin.
if you mean this
it is TextInputLayout
Add the dependency for the design support library inside the build.gradle (Module: app) file as shown below.
implementation 'com.google.android.material:material:<version>'
the latest version at this time is 1.2.0-alpha03 you can see latest version from mvnrepository
Then, you can use it like this in your xml layouts.
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/myTextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/my_editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/YOUR_HINT"
android:singleLine="true"
android:textColor="#color/colorDarkestGray" />
</com.google.android.material.textfield.TextInputLayout>
This is TextInputLayout and you can use editText as child in it like this :
At first add the dependency for the design support library inside the build.gradle file as shown below.
implementation 'com.android.support:design:25.3.1'
And if you are using AndroidX use this :
implementation 'com.google.android.material:material:1.0.0'
Second ,Then implement that like this :
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="#dimen/activity_horizontal_margin">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Floating Hint Enabled Default" />
</android.support.design.widget.TextInputLayout>
Android TextInputLayout Features
1-Enabling/Disabling floating hints
2-Enabling/Disabling floating hint animation
3-Displaying Error Messages
4-Showing Character Counter
5-Password Visibility Toggle and . . .
I want to drag and drop elements into the Design View but I just can't. I can't even see the attributes aside when click into the screen or the default TextView that says 'Hello World!'. I tried restarting Android Studio, rebuild the project, and I still have the problem.
The code below is from my file 'activity_main.xml'.
How did happened?
I just tried to add a 'GridLayout' into the screen design, but to use it I had to install a library to use that grid layout and since I did that, I can't use the design view anymore.
Even I get an 'IDE Fatal Error' (screenshot below).
error ide image:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<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>
Remove
implementation 'com.android.support.constraint:constraint-layout:+'
from your build.gradle (app)
Hopefully Solve this problem
https://imgur.com/a/arLyGYR
The design tab for my Android Studio doesn't display even the starting Hello World or my project name, does anybody know how to make this display and update as I write my program ?
edit: I'm not sure how the code will help, the tutorial im following says that the design tab should look like this upon opening https://imgur.com/a/FRgc2G1 and update as I code. I think it's a problem with the settings of android studio because the only code i've changed is what they have told me to.
<?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"
android:background="#0d7429"
tools:context=".MainActivity"
tools:layout_editor_absoluteY="25dp">
<android.support.v7.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/colorPrimaryDark"
android:text="#string/Hello_World_Text"
android:textColor="#android:color/white"
android:textSize="30sp"
app:fontFamily="cursive" />
</android.support.constraint.ConstraintLayout>
It is because you have an error in your xml.
Changing TextView to android.support.v7.widget.AppCompatTextView works if you want to use "app" name space prefix for app:fontFamily. However,you can also use android namespace prefix for fontFamily but it is only compatible with API version 16 and higher.
go to app/res/values/styles.xml
if it says:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
change it to
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
I have a listActivity that displays via an adapter an xml feed fetched from the web, adn the layout file activity_list_feed.xml :
`<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false"
android:transcriptMode="normal"
/>`
In the graphic editor i cannot drag a button into this layout, and when i try to hardcode as per this file :
`<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="#+id/addBtn"
android:text="Add New Item"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="addItems"/>
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false"
android:transcriptMode="normal"
/>
</LinearLayout>`
i get a compile error message :
java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to android.widget.TextView
How can i add a button on top of the list because i want to refresh the pull.thank you.
The code that you provided actually works in its current state in Android Studio:
Make sure that in your java code, you are referencing the correct item. Make sure that you're setting the overall layout to be that layout, and THEN doing findViewById(R.layout.addBtn).
Also, try changing the Android Version in your IDE to 22 (as I have it set in the top right corner of the picture). That may solve your error.
I managed to add the button in the editor and this without setting to API 22 as per your picture. However the program didn't compile still.
The message error "ArrayAdapter requires the resource ID to be a TextView" meant i didn't provide the right argument to the adapter.
According to this answer :
"ArrayAdapter requires the resource ID to be a TextView" xml problems
it appears that the choice of the constructor is important, since i wanted to add a button in the view, i must use the constructor with 4 arguments (the additional argument being the id of the view):
http://developer.android.com/reference/android/widget/ArrayAdapter.html#ArrayAdapter(android.content.Context,int,int,java.util.List)
Using this constructor solved the problem.
I would like to be able to define a ShapeDrawable in my layout file and then inflate that so I can draw on it.
I have followed the tutorial on the android developers' site but I cannot see how I reference my ShapeDrawable in my main class file.
How do I actually inflate it?
I have put the following the following into my layout file:
<com.example.shapedrawable.CustomDrawableView
android:id="#+id/customDrawableView"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
Once you have defined the ShapeDrawable in its own XML file, you need to add the following to the layout.xml where you want it to be included:
<ImageView
android:src="#drawable/shapeDrawable_filename"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
If you want to do it programmatically, I don't have an answer (yet), but from your question, it seems this should work!
Let me know if that helps ;)