any View not appearing in the android studio editor - android

when building the app the view i've put in appears but in the editor it is not appearing, and sometimes when i create a ImageView some of the images I pasted in the drawables causes rendering problems. I recently updated my android studio and now it is full of bugs.the image attached below is a new project, I only added image view and convert it to relative layout since constraint layout gives me a ton of errors. thank you for answering my question.
<?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:visibility="visible"
tools:context=".MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Hello World!"
android:textAppearance="#style/TextAppearance.AppCompat"
android:visibility="visible" />
<ImageView
android:id="#+id/imageView"
android:layout_width="30dp"
android:layout_height="30dp" />
</RelativeLayout>
P.S.
the image view's src or compatsrc stuff, I've deleted it since it causes errors when building just to test it out. and when opening existing projects the app folder seems to be deleted/moved.
here is the gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.rowel.animation"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

SDK 28 is buggy and has lots of layout issues and program bugs.
you can try adding Base. to your theme's parent in styles.xml
eg:
<resource>
<style name="AppTheme" parent="Theme.AppCompat">
...
to
<resource>
<style name="AppTheme" parent="Base.Theme.AppCompat">
...
if doesn't work, then try Invalidating Cache
if that doesn't work either, try changing targetSdkVersion to 27 or below

Change your compileSdkVersion and targetSdkVersion to 27
and also change this
implementation 'com.android.support:appcompat-v7:27.1.1'

Related

Font scaling doesn't work after implementing androidx biometric library on Android 7

I'm having issues in my app after implementing the biometric library from androidx on a device with Android 7. The issues started in my main app when changing the font size in the phone's accessibility settings and the text size in the app didn't change. After pinpointing the problem, I have created a dummy app with a single "hello world" activity and I have found out that even only by declaring the library's dependency in app.gradle reproduces the bug.
This is the activity's xml:
<androidx.constraintlayout.widget.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"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
And this is the build.gradle:
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.fontscaletestapplication"
minSdkVersion 23
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation "androidx.biometric:biometric:1.0.1"
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
Worth mentioning is that if I remove the dependency for androidx biometric, the font scaling works without any problems, but as soon as I add the dependency, changing the font size has no impact on the size of the font in the app.
From what I noticed in the main app, I think it has something to do with the application context and the application resources, but I can't figure out what the problem is. I have tested on a HTC 10 with Android 7 and on emulator with API 24. Another thing worth mentioning is that the font scaling works on Android 9 and 10.
Is there something I'm missing?
Thank you.
It's caused by https://issuetracker.google.com/issues/140607881
According to the bug:
"All version before API 26 are affected, Android 8.0 is the first version where is possible to change font size globally with app compat 1.1.0"
"Fixed in latest AppCompat 1.2.0-alpha02"
I tested the latest 1.2.0-beta01 and the fix works. Here are all the versions of appcomat https://developer.android.com/jetpack/androidx/releases/appcompat.

AFTER adding a style resource file got Android resource linking failed

After I´ve created a style in my application which uses a gridlayout, build is not working anymore.
I´ve tried Invalidate Caches & restart, and change some gradle dependencies, but since I don´t understand what´s going on, I could not fix it.
the design was working ok without the style resource file, after I´ve created it for the buttons, the build start to fail.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.GridLayout
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"
android:layout_margin="0.5dp"
app:columnCount="2"
app:rowCount="4"
app:alignmentMode="alignBounds"
tools:context=".MainActivity">
<Button style="#style/MainButton"
android:id="#+id/b_1"
app:layout_column="0"
app:layout_row="0"
android:text="#string/boletim"
android:onClick="OnClick"
android:background="#drawable/ic_boletim" />
<Button
style="#style/MainButton"
android:id="#+id/b_2"
app:layout_column="1"
app:layout_row="0"
android:text="#string/salarios"
android:background="#drawable/ic_salario" />
</android.support.v7.widget.GridLayout>
this is my button resource file, which is created in the values folder
<resources>
<!-- estilo do botão -->
<style name="MainButton" >
<item name="android:layout_margin">10dp</item>
<item name="android:textColor">#141210</item>
<item name="android:textStyle">bold</item>
<item name="android:textSize">24dp</item>
<item name="layout_columnWeight">1</item>
<item name="layout_rowWeight">1</item>
<item name="layout_gravity">fill_horizontal|fill_vertical</item>
</style>
</resources>
and perhaps this is usefull too, some build.gradle infos
compileSdkVersion 26
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner" minSdkVersion 23
compileOptions {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}
buildToolsVersion = '28.0.3' }
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:2.0.0-
beta1'
testImplementation 'junit:junit:4.13-beta-3'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-
core:3.0.2'
implementation 'com.android.support:gridlayout-v7:27.0.0'
}
I´ve found the solution:
in the gradle app properties file the compile versionarget and build must match:
compileSdkVersion 28 and targetSdkVersion 28 and buildToolsVersion = '28.0.3'

Error recognizing dataBinding class android

in one of my projects I have started to implement dataBinding in the main activity by separating the data in a class called view, in another class called viewModel and in the model class. Using these classes and the dataBinding, the application has been compiled correctly, but when I put the classes in different packages to follow the MVVM architecture, the self-generated class named ActivityLoginBinding does not recognize the class that is inside the ViewModel package. I have already done searches of different projects to see if it was my mistake at syntax level, but they are well written. I have also noticed that all the projects are divided into different packages and work correctly. Any idea why this happens and how could it be solved? Thank you.
my xml
<?xml version="1.0" encoding="utf-8"?>
<layout 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">
<data>
<variable
name="student3"
type="com.juan97.prueba.ViewModel.Student3ViewModel"/>
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".View.MainActivity">
<TextView
android:layout_marginTop="50sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:hint="#{student3.hint1}"/>
<TextView
android:layout_marginTop="50sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:hint="#{student3.hint2}"/>
</LinearLayout>
</layout>
gradle module app
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.juan97.prueba"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dataBinding {
enabled = true
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
Different packages I have:
compile error

Android Studio 3.1.3, design view is always empty

I'm new to android development and I have this problem with my Android Studio 3.1.3 demo project or any project that I create.
Even though that I can drag and drop different controls on my design view (ConstraintLayout) but nothing shows on the design view, it shows for a split sec and then it disappears.
I can see all the elements which I drag and drop in activity_main.xml Text tab, Component Tree and even in run mode, but not in design tab, nothing shows in design view and it is always blank not even hello world shows on it.
I tried Invalidate Cache Restart, Restarting my PC, changing Zoom - In and out, Inferring constraints, but no luck. Controls
I can't do much unless I see things in design view.
Empty Design View:
Run mode view
activity_main.xml
<?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"
tools:context=".MainActivity">
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:id="#+id/button4"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:text="Button" />
<android.support.constraint.Guideline
android:id="#+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_begin="20dp" />
<CheckBox
android:id="#+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CheckBox"
tools:layout_editor_absoluteX="154dp"
tools:layout_editor_absoluteY="181dp" />
</android.support.constraint.ConstraintLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.libra.myapplication">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.libra.myapplication"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
Ok my problem is solved!
The following classes could not be instantiated: - android.support.v7.widget.Toolbar
I changed the res/values/styles.xml file from this:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
to this:
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
and that solved the problem
Another workaround is to edit GradleScripts/build.gradel(Module app)
-> implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
into implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
and, if there,
-> implementation 'com.android.support:design:28.0.0-alpha3'
into implementation 'com.android.support:design:28.0.0-alpha1'
SAVE and + SyncNow
I have been having the same problem and found that this hack worked for me. I have changed the versions in app file located in the Gradle Scripts/ build.gradle(Module:app) to versions 27. CompileSdkVersion, minSdkVersion, targetSdkVersion and implementation 'com.android.support:appcompat-v7:27.0.0'. These are listed on line 4,7,8 and 23.. (it might be different for you).
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.fiv4.masterapp"
minSdkVersion 27
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
For those that nothing works in this page or in the whole internet(just like me), try to uninstall your android studio then reinstall. (You don't have to uninstall sdks, avd. Settings can also stay the same. Just the main program needs uninstall)
When you reinstall Android Studio, change the version to 27 as in the image. That is it, hope it works for you too
Use stable version of support libraries.
The problem is when you are using unstable alpha support libraries. See stable libraries versions on google maven repo.
At the time of answer, most stable version of support:appcomact-v7 is 28.0.0-rc02
Replace
implementation 'com.android.support:appcompat-v7:28.0.0-alpha3' // less stable alpha
With
implementation 'com.android.support:appcompat-v7:28.0.0-rc02' // more stable
Sync, Just Restart AS. Problem resolved !
Track support:appcomact-v7 stable versions
Track support:design stable versions
Track support:recyclerview-v7 stable versions
Track support:cardview-v7 stable versions
Your layout has problem with the CheckBox widget. It has no constraint. tools:layout_editor_absoluteX and tools:layout_editor_absoluteY are only affect on design mode, but not in real running app.
Note: Don't drag/drop the widget on design view, it will generate many weird properties that not gonna work in all case, like the two properties you got. Do it in the code instead. If you want the CheckBox to be in center, do like this:
<CheckBox
android:id="#+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CheckBox"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />
This will remove the error icon at the CheckBox, then a refresh may help.
Go to res/values/styles.xml file...
on line 4, its always...
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
Change this with
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
No need to save the file, it will automatically be saved. Go to activity_main.xml --> Design (View) ...it should be showing it now.

Rendering Problems:Binary XML file line #-1: No start tag found

Initially I was getting error in Manifest file at android:theme="#style/AppTheme" . I look for the solution and from this solution Android Studio: Error in Layout Files - Header expected , I get rid of that error.
But on the other hand I started getting errors in all my layout preview like this
xml file for the above image is
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context=".MainActivity" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Process Inbox"
android:id="#+id/heading"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:gravity="center"
android:textColor="#964acf"
android:textStyle="bold" />
<ExpandableListView
android:id="#+id/inbox_expandable_list"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/heading">
</ExpandableListView>
</RelativeLayout>
I tried undo the changes but no success, can anyone guide me the reason or solution for the problem.
here is my app.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.abc.xyz"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'io.realm:realm-android:0.82.1'
compile 'com.google.code.gson:gson:2.2.2'
}
There's a similar question here and here
Moving the problematic tab between different split views did the trick in a second.

Categories

Resources