I have strange problem. I use custom item of card view with such code:
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView 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"
app:cardCornerRadius="4dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="4dp"
>
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:padding="5dp"
android:id="#+id/pizzaImage"
android:layout_marginRight="5dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/Header"
android:text="Header Text"
android:textSize="25sp"
android:layout_alignParentTop="true"
android:layout_toEndOf="#id/pizzaImage"
android:layout_marginBottom="4dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/contentText"
android:text="Some text about pizza and other reciepe information"
android:textSize="15sp"
android:layout_below="#id/Header"
android:layout_toEndOf="#id/pizzaImage"/>
</RelativeLayout>
</com.google.android.material.card.MaterialCardView>
So when I'm trying to buidl project I have dependency issues:
Dependency 'androidx.appcompat:appcompat-resources:1.6.0' requires libraries and applications that
depend on it to compile against version 33 or later of the
Android APIs.
:app is currently compiled against android-32.
Recommended action: Update this project to use a newer compileSdkVersion
of at least 33, for example 33.
Note that updating a library or application's compileSdkVersion (which
allows newer APIs to be used) can be done separately from updating
targetSdkVersion (which opts the app in to new runtime behavior) and
minSdkVersion (which determines which devices the app can be installed
on).
And when I change SDK in gradle to 33, I have NO dropdown helpers inside RelativeLayout, when coding in xml file. No layout_with, no textSize. When i change back to 32, they're back, and at least dependency issues come back again too.
So when I change the
androidx.appcompat:appcompat-resources:1.6.0 to androidx.appcompat:appcompat-resources:1.5.0
I can't start the app.
What is wrong?
Related
I've been trying to use MaterialToggleGroup in an Android project, but it is not working properly. The problem is that it always seems to be empty, no matter what you put inside it.
I'm using a very simple layout, with a LinearLayout that includes the group and a ListView. The group itself contains two buttons.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical" >
<com.google.android.material.button.MaterialButtonToggleGroup
android:id="#+id/toggle_group"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<com.google.android.material.button.MaterialButton
android:id="#+id/button1"
style="?attr/materialButtonOutlinedStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 1" />
<com.google.android.material.button.MaterialButton
android:id="#+id/button2"
style="?attr/materialButtonOutlinedStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 2" />
</com.google.android.material.button.MaterialButtonToggleGroup>
<ListView
android:id="#+id/listado"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
/>
</LinearLayout>
In the editor it looks like this:
toggle group with wrap_content
If I change the hight and set it, for example, to 30dp, it shows up but as if it was empty, proving that it is being inserted but it's no working properly:
toggle group with 30dp
Project is in Java and its dependencies are pretty much not updated. The problem can be seen on editor but also when app is running on emulator and physical device.
What I've tried so far:
Invalidating caches/restarting.
Clean and rebuild project.
Upgrading all dependencies, including Gradle build tools, material and app compat libraries.
Test it in another layout, same result.
Test some other Material components, they work fine.
Create a new project and use the component, no problems found, seems that the problem is in this project.
I'm running out of ideas, but I'd like to avoid creating my own component to achieve the same result.
Thanks for your help.
My program is running correctly, but this error is being displayed in the compiler. How to fix it?
No answer regarding this can be found on Google, I checked quite many times.
activity_main
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:id="#+id/mainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<!-- username-->
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/username_TIL"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="100dp"
android:elevation="2dp">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/username_TIET"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="#string/username" />
</com.google.android.material.textfield.TextInputLayout>
<!-- password-->
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/password_TIL"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:layout_below="#id/username_TIL">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/password_TIET"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="password"/>
</com.google.android.material.textfield.TextInputLayout>
<!-- confirmPassword-->
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/confirmPassword_TIL"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:layout_below="#id/password_TIL">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/confirmPassword_TIET"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="#string/confirm_password"/>
</com.google.android.material.textfield.TextInputLayout>
<!-- SignIn-->
<androidx.appcompat.widget.AppCompatButton
android:id="#+id/signIn_BTN"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="#string/sign_in"
android:textColor="#android:color/white"
app:cornerRadius="50dp"
android:elevation="2dp"
android:layout_below="#id/confirmPassword_TIL"
android:layout_marginTop="20dp"
android:layout_centerHorizontal="true"
android:background="#android:color/holo_blue_light"/>
</RelativeLayout>
MainActivity has nothing in it - initialised
Manifest File also has nothing extra added to it. Any explanations towards why is this error occurring. Also one more error is being displayed.
E/InputTransport: ro.sf.lcd_density must be defined as a build property
I had the same problem but mine was because of screen density. You may need to revise your images or icons size if any in the drawable folder then generate a copy to following directories.
res/
drawable-xxxhdpi/
example.png
drawable-xxhdpi/
example.png
drawable-xhdpi/
example.png
drawable-hdpi/
example.png
drawable-mdpi/
example.png
For more info read here
To eliminate this error message, add the following line to the build.prop file located in the /system folder on the device:
ro.sf.lcd_density=160
This sets the display density to 160 dpi, which is the lowest among currently supported devices. You can adjust it to match the specific density of your device.
Note: You need to have root access to the device in order to edit the build.prop file. Since this can cause issues on some devices, it is to make a backup of the original file before making any changes.
I'm using android data binding and it is working fine whenever I'm not using the include tag.
If I included a view using the tag (even it is displaying on the app) but the data binding object doesn't recognize the views of the included layout. These are my layout files.
internet_unavailable.xml
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical">
<TextView
android:id="#+id/internet_textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:gravity="center_horizontal"
android:text="#string/msg_internet_unavailable"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/colorSecondaryText" />
<Button
android:id="#+id/internet_button_retry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="#dimen/internet_margin_top"
android:backgroundTint="#color/colorAccent"
android:paddingEnd="#dimen/internet_padding_h"
android:paddingStart="#dimen/internet_padding_h"
android:text="#string/str_retry"
android:textColor="#android:color/white" />
</LinearLayout>
</layout>
fragment.xml
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.ncimsl.fragments.ProgressNotesFragment">
<include
android:id="#+id/progress_notes_internet"
layout="#layout/internet_unavailable" />
<ProgressBar
android:id="#+id/progress_notes_progressbar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/progress_notes_swiperefreshlayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/progress_notes_recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v4.widget.SwipeRefreshLayout>
</FrameLayout>
</layout>
As you can see the progressBar, swipeRefreshLayout and the recyclerView are displaying at the suggestions except the included layout and the views inside it.
Any idea to fix this?
Thanks Guys. I think it was an issue in Android Studio of my PC. I opened the project on another PC and now it's working. Probably I should re-install the Android Studio and give a try.
Performing Rebuild solves the issue for me.
Following is the screenshot from my AndroidStudio after Rebuild:
My build.gradle:
android{
...
dataBinding {
enabled = true
}
}
My gradle.properties:
android.databinding.enableV2=true
Wanna share my experience to those who still struggle... I had the same problem and it wasn't resolved until turning on viewBinding (in addition to dataBinding) in app's build.gradle. (Android Studio 4.2
buildFeatures {
dataBinding = true
viewBinding = true
}
I'm using Android Studio for application development and I have a problem with placing elements in the screen.
For example: I'm trying to place a button to the right of the screen and in the studio its shown to the right of the screen but when I install the app in my smartphone i see it in the left of the screen (my smartphone is right to left configured).
How can i resolve it? (I use RelativeLayout if that matters).
Thanks!
illustration image
It would be easier to answer your question if you included some code. However, assuming your button is inside a relative parent layout which fills the screen, adding this to your button's xml code will make it align to the right:
android:layout_alignParentRight="true"
ie.
<Button
android:id="#+id/btn"
android:layout_width="145dp"
android:layout_height="75dp"
android:layout_alignParentRight="true"
android:onClick="btnclick"
android:text="Click!"
android:textSize="30sp" />
Or to make it really easy, replace your entire XML with:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:weightSum="1">
<Button
android:id="#+id/btn"
android:layout_width="145dp"
android:layout_height="75dp"
android:onClick="btnclick"
android:text="Click!"
android:textSize="30sp"
android:layout_alignParentRight="true"/>
</RelativeLayout>
The code for those who requested:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:weightSum="1"><![CDATA[
android:splitMotionEvents="true"
tools:context="tomer.newapp.MainActivity"
tools:layout_editor_absoluteY="81dp"
tools:layout_editor_absoluteX="0dp">
]]>
<Button
android:id="#+id/btn"
android:layout_width="145dp"
android:layout_height="75dp"
android:layout_column="2"
android:layout_row="2"
android:onClick="btnclick"
android:text="Click!"
android:textSize="30sp"
tools:layout_editor_absoluteX="223dp"
tools:layout_editor_absoluteY="140dp"
android:layout_marginLeft="11dp"
android:layout_marginStart="11dp"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
Note that the absolute values that you are using are in the tools namespace - this means they are not compiled into your app.
tools:layout_editor_absoluteX="223dp"
tools:layout_editor_absoluteY="140dp"
That is probably why you are getting this kind of behavior.
Remove them and then see if the button moves to the left of the screen.
More about tools namespace - here
You mentioned "(my smartphone is right to left configured)".
This could be a dud answer, but...
With the layout_editor, for either the "gravity" or "layout_gravity" properties, there is a "right", "left", or "start" and "end". In English, one starts writing at the left, and ends at the right. In Arabic, for example, one starts at the right and ends left. Any chance your property says "end", instead of "right"?
I'm using CardView as rows in a listview. The cards in Android 4.0 -4.4 are well spaced, just as desired, but in Andorid 5.0, they aren't.
Here are the screenshots:
For Android 5.0:
http://i.imgur.com/70E8Tpf.png
for pre-lollipop, and the way I want it:
http://i.imgur.com/9UsJc1o.jpg?1
Here's the code for the CardView:
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:cardview="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:layout_width="match_parent"
android:stateListAnimator="#anim/anim"
android:layout_margin="5dp"
android:clickable="true"
cardview:cardElevation="5dp"
cardview:cardBackgroundColor="#color/WhiteSmoke"
cardview:cardCornerRadius="10dp"
android:layout_height="wrap_content"
android:longClickable="true"
android:background="#android:drawable/dialog_holo_light_frame">
Here's the code for the listview these cards are a part of:
<ListView
android:id="#android:id/list"
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/toolbar"
android:orientation="vertical">
What is it that's causing the cards to not be spaced on Android 5.0? I hope I've provided the information needed.
Thank you!
Okay, I solved the issue by adding :
cardview:cardUseCompatPadding="true"
You can read about it here - https://developer.android.com/reference/android/support/v7/widget/CardView.html#attr_android.support.v7.cardview:cardUseCompatPadding