Create Mobile App for coursework on Kotlin. I ran into a problem that for some reason I can't nest a fragment in a FragmentContainerView. I couldn't find on the internet how to fix it.
Code in gradle
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}
android {
compileSdk 33
defaultConfig {
applicationId "com.example.historicalsaratovnav"
minSdk 28
targetSdk 33
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
dataBinding{enabled=true}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.appcompat:appcompat:1.6.0'
implementation 'com.google.android.material:material:1.8.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
implementation 'com.google.android.material:material:1.8.0'
implementation("androidx.navigation:navigation-fragment-ktx:2.5.3")
implementation("androidx.navigation:navigation-ui-ktx:2.5.3")
implementation 'androidx.core:core-splashscreen:1.0.0'
implementation "androidx.fragment:fragment-ktx:1.6.0-alpha04"
}
Code layout
<androidx.drawerlayout.widget.DrawerLayout
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=".Layout_Activity">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<androidx.fragment.app.FragmentContainerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="1"
android:id="#+id/conteiner_fragment"
app:defaultNavHost="true"
android:gravity="center"/>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:labelVisibilityMode="labeled"
android:background="#color/white"
app:menu="#menu/menu"
android:id="#+id/bottom_navigation_view"
>
</com.google.android.material.bottomnavigation.BottomNavigationView>
</FrameLayout>
</androidx.drawerlayout.widget.DrawerLayout>
Code file KT
import android.content.Context
import android.os.Binder
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.AttributeSet
import android.view.View
class Layout_Activity : AppCompatActivity() {
lateinit var binding: Layout_ActivityBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = Layout_ActivityBinding.inflate(layoutInflater)
setContentView(binding.root)
binding.Main.setOnClickListener {
replaceFragment(Main_App_Screen_Fragment())
}
binding.List.setOnClickListener {
}
binding.Map.setOnClickListener {
}
binding.Profile.setOnClickListener {
---
}
binding.Settings.setOnClickListener {
}
}
private fun replaceFragment(fragment: Main_App_Screen_Fragment) {
val fragmentManager = supportFragmentManager
val fragmentTransaction = fragmentManager.beginTransaction()
fragmentTransaction.replace(R.id.conteiner_fragment, fragment)
fragmentTransaction.commit()
}
}
Tried adding dependencies to Gradle, but nothing changed. Also, when I just created the binding, NameBinding was automatically generated for me. After that, I erased it and made it custom and I can’t do anything else because the application does not work.
please do this in gradle
android {
buildFeatures {
viewBinding true
dataBinding true
}
}
Assume that you have a layout .xml named as xyz_activity.xml
then android will create a binding named XyzActivityBinding
suggest you to check your .xml name
Also add
buildFeatures {
viewBinding true
}
in your app build.gradle
If this solution not helping you recommend you to try this solution once. You facing this error because of 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>
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".settingModuleFragment.itemList.ItemsListActivity">
<include
android:id="#+id/toolbarItemListLayout"
layout="#layout/toolbar" />
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
ads:adSize="BANNER"
ads:adUnitId="#string/banner_ad_id">
</com.google.android.gms.ads.AdView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="#+id/frame_fl"
android:layout_alignParentTop="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/relative_rl">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="#dimen/_8sdp"
android:id="#+id/rv_ll"
android:focusableInTouchMode="true"
android:orientation="vertical">
<EditText
android:id="#+id/search_edTxt"
android:layout_width="match_parent"
android:layout_height="#dimen/_35sdp"
android:paddingStart="#dimen/_4sdp"
android:background="#drawable/write_bg_color"
android:drawableStart="#drawable/ic_search_24"
android:inputType="text" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rv_item"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
</LinearLayout>
<TextView
android:id="#+id/noItems_Tv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="#dimen/_16ssp"
android:gravity="center"
android:visibility="gone"
style="#style/Label_Normal"
android:text="#string/you_haven_t_added_any_items"/>
</FrameLayout>
<RelativeLayout
android:id="#+id/relative_rl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/_8sdp"
android:layout_alignParentBottom="true"
android:layout_marginEnd="#dimen/_8sdp"
android:layout_marginBottom="#dimen/_5sdp"
android:layout_gravity="bottom">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/total"
android:textSize="#dimen/_14ssp"
android:textColor="#color/black"
android:gravity="center"
android:layout_alignParentStart="true"
android:fontFamily="#font/lato_bold"/>
<TextView
android:id="#+id/total_item_count_Tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:fontFamily="#font/lato_bold"
android:gravity="center"
android:text="#string/_0_0"
android:textColor="#color/black"
android:textSize="#dimen/_14ssp" />
<TextView
android:id="#+id/total_amount_count_Tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/lato_bold"
android:gravity="center"
android:layout_alignParentEnd="true"
android:text="#string/_0_0"
android:textColor="#color/black"
android:textSize="#dimen/_14ssp" />
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
</layout>
This is used if you need to use the tag whenever you are using DataBinding for the compiler to understand the special tags and generate the DataBinding class with the right variables and methods.
Original answer: https://stackoverflow.com/a/44682671/19674027
Yesterday everything was ok, but today I've started to working again in my app, in the xml file of an activity but Android Studio show nothing on the phone interface (That one that is located normally to the right, just next to the XML code.) It says that it is a render problem.
Here you can see that the layou is displayed normally but i can't see my edits until I run the app
java.lang.IllegalArgumentException: No drawer view found with gravity RIGHT
at androidx.drawerlayout.widget.DrawerLayout.openDrawer(DrawerLayout.java:1736)
at androidx.drawerlayout.widget.DrawerLayout.openDrawer(DrawerLayout.java:1722)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.android.layoutlib.bridge.util.ReflectionUtils.invoke(ReflectionUtils.java:56)
at com.android.layoutlib.bridge.android.support.DrawerLayoutUtil.openDrawer(DrawerLayoutUtil.java:59)
at com.android.layoutlib.bridge.android.support.DrawerLayoutUtil.openDrawer(DrawerLayoutUtil.java:53)
at android.view.BridgeInflater.postInflateProcess(BridgeInflater.java:577)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.postInflateProcess(RenderSessionImpl.java:702)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.postInflateProcess(RenderSessionImpl.java:707)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:338)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:373)
at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:141)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:713)
at com.android.tools.idea.rendering.RenderTask.lambda$inflate$6(RenderTask.java:844)
at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1604)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Note that this errors doesnt show in the logcat, because all is running except the visualizator.
It says something like there is not drawer view with gravity RIGHT, and off course there is not. But IDK why is now searching for it.
Here is my code. I have already worked with this configuration so I think this is not the problem.
<androidx.drawerlayout.widget.DrawerLayout
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:id="#+id/drawer_layout_dar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="end"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.google.android.material.appbar.MaterialToolbar
android:id="#+id/toolbar_dar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/itemBlueDark"
app:title="Sube tu objeto"/>
<com.google.android.material.textfield.TextInputLayout
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:id="#+id/title_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Categoría"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
>
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/spinner_Text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:inputType="none"
/>
</com.google.android.material.textfield.TextInputLayout>
<Spinner
android:id="#+id/spinner"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#android:color/transparent"
android:spinnerMode="dialog"
tools:listitem="#layout/spinner_layout"
/>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/nombre_objeto"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginTop="10dp"
android:layout_marginRight="12dp"
android:background="#color/white"
android:hint="#string/nombre_objeto">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/nombre_objeto_editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/desc_objeto"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginTop="10dp"
android:layout_marginRight="12dp"
android:layout_marginBottom="12dp"
android:background="#color/white"
android:hint="#string/descripcion_objeto">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/desc_objeto_editText"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
<ImageView
android:id="#+id/img_objeto"
android:layout_width="274dp"
android:layout_height="240dp"
android:layout_gravity="center"
android:layout_marginTop="24dp"
android:src="#drawable/sin_foto" />
<Button
android:id="#+id/btn_enviar_imagen"
android:layout_width="wrap_content"
android:layout_height="45dp"
android:layout_gravity="center"
android:layout_marginTop="60dp"
android:layout_marginBottom="40dp"
android:background="#drawable/forma_btn"
app:backgroundTint="#color/itemBlueDark"
android:text="Subir" />
<Button
android:id="#+id/btn_listaUsuarios"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</Button>
</LinearLayout>
<com.google.android.material.navigation.NavigationView
android:id="#+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/cabecera_menu"
app:menu="#menu/menu_drawer" />
</androidx.drawerlayout.widget.DrawerLayout>
here you can see that there is a problem w/ the Layout Rendering Engine. I've tried to enable/disable it but it seems it does not work
Here you can see other errors related to the rendering
Althouhg other XML files have the same render issues, AndroidStudio display the desing visualizator properly
EDIT: Here are my dependencies, maybe some of this are wrong, but i doubt it.
plugins {
id 'com.android.application'
id 'com.google.gms.google-services'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.Trueque"
minSdkVersion 19
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.3.0'
//para las cajas de texto
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
//Para dependencias de firebase
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
//Para las tabs deslizantes
implementation "androidx.viewpager2:viewpager2:1.0.0"
// Import the BoM for the Firebase platform
implementation platform('com.google.firebase:firebase-bom:28.2.0')
// Declare the dependency for the Realtime Database library
// When using the BoM, you don't specify versions in Firebase library dependencies
implementation 'com.google.firebase:firebase-database'
// Import the BoM for the Firebase platform
implementation platform('com.google.firebase:firebase-bom:28.2.0')
// Declare the dependency for the Firebase Authentication library
// When using the BoM, you don't specify versions in Firebase library dependencies
implementation 'com.google.firebase:firebase-storage:20.0.0'
implementation 'com.google.firebase:firebase-auth:21.0.1'
}
I have fixed it by deleting the following lines in the XML file.
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/title_spinner"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:hint="Categoría">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/spinner_Text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:inputType="none" />
</com.google.android.material.textfield.TextInputLayout>
<Spinner
android:id="#+id/spinner"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#android:color/transparent"
android:spinnerMode="dialog"
tools:listitem="#layout/spinner_layout" />
I added two floating action buttons on a fragment but I always get following error:
Invalid drawable added to LayerDrawable! Drawable already belongs to another owner but does not expose a constant state
<RelativeLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_margin="30dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_weight="1"
android:id="#+id/scrollView"
android:layout_marginRight="30dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/layout_main_account">
<TextView
android:text="Name"
android:textStyle="bold"
android:layout_marginTop="30dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tv_activity_main_account_name_label"/>
<EditText
android:enabled="false"
android:inputType="none"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/et_activity_main_account_name_label_value"/>
</LinearLayout>
</ScrollView>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="0dp"/>
<android.support.design.widget.FloatingActionButton
android:backgroundTint="#000"
android:layout_marginBottom="5dp"
android:layout_marginRight="10dp"
app:layout_anchorGravity="bottom"
android:layout_width="wrap_content"
android:layout_gravity="bottom|end"
android:layout_height="wrap_content"
android:src="#drawable/ic_edit_account"
android:id="#+id/fbtn_activity_main_account_edit_account"/>
<android.support.design.widget.FloatingActionButton
android:backgroundTint="#000"
android:layout_marginBottom="5dp"
app:layout_anchorGravity="bottom"
android:layout_width="wrap_content"
android:layout_gravity="bottom|end"
android:layout_height="wrap_content"
android:src="#drawable/ic_home_account"
android:id="#+id/fbtn_activity_main_account_manage_addresses"
app:layout_anchor="#id/fbtn_activity_main_account_edit_account"/>
</LinearLayout>
</RelativeLayout>
drawable -> ic_edit_account.xml
<vector android:height="24dp" android:viewportHeight="60.017"
android:viewportWidth="60.017" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FFFFFF" android:pathData="M59.144,3.731l-2.85,-2.851c-1.164,-1.161 -3.057,-1.162 -4.221,0.001l-3.126,3.126H0v56h56V11.097l0.305,-0.305l0,0l2.839,-2.839C60.308,6.789 60.308,4.895 59.144,3.731zM20.047,36.759l3.22,3.22l-4.428,1.208L20.047,36.759zM52.062,12.206L47.82,7.964l1.414,-1.414l4.243,4.242L52.062,12.206zM50.648,13.62L25.192,39.076l-4.242,-4.242L46.406,9.378L50.648,13.62zM54,13.097v44.91H2v-52h44.947L18.829,34.127l-0.188,0.188l-2.121,7.779l-1.226,1.226c-0.391,0.391 -0.391,1.023 0,1.414c0.195,0.195 0.451,0.293 0.707,0.293s0.512,-0.098 0.707,-0.293l1.226,-1.226l7.779,-2.123l26.351,-26.35h0l0.447,-0.447L54,13.097zM57.73,6.539l-2.839,2.839l-4.243,-4.243l2.839,-2.839c0.384,-0.384 1.009,-0.383 1.393,0l2.85,2.85C58.114,5.529 58.114,6.155 57.73,6.539z"/>
</vector>
drawable -> ic_home_account.xml
<vector android:height="24dp" android:viewportHeight="512"
android:viewportWidth="512" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FFFFFFFF" android:pathData="M506.555,208.064L263.859,30.367c-4.68,-3.426 -11.038,-3.426 -15.716,0L5.445,208.064c-5.928,4.341 -7.216,12.665 -2.875,18.593s12.666,7.214 18.593,2.875L256,57.588l234.837,171.943c2.368,1.735 5.12,2.57 7.848,2.57c4.096,0 8.138,-1.885 10.744,-5.445C513.771,220.729 512.483,212.405 506.555,208.064z"/>
<path android:fillColor="#FFFFFFFF" android:pathData="M442.246,232.543c-7.346,0 -13.303,5.956 -13.303,13.303v211.749H322.521V342.009c0,-36.68 -29.842,-66.52 -66.52,-66.52s-66.52,29.842 -66.52,66.52v115.587H83.058V245.847c0,-7.347 -5.957,-13.303 -13.303,-13.303s-13.303,5.956 -13.303,13.303v225.053c0,7.347 5.957,13.303 13.303,13.303h133.029c6.996,0 12.721,-5.405 13.251,-12.267c0.032,-0.311 0.052,-0.651 0.052,-1.036v-128.89c0,-22.009 17.905,-39.914 39.914,-39.914s39.914,17.906 39.914,39.914v128.89c0,0.383 0.02,0.717 0.052,1.024c0.524,6.867 6.251,12.279 13.251,12.279h133.029c7.347,0 13.303,-5.956 13.303,-13.303V245.847C455.549,238.499 449.593,232.543 442.246,232.543z"/>
</vector>
build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.atta"
minSdkVersion 23
targetSdkVersion 26
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:26.1.0'
implementation 'com.android.support:design:26.1.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'
// retrofit, gson
implementation 'com.google.code.gson:gson:2.6.2'
implementation 'com.squareup.okhttp3:okhttp:3.8.0'
implementation 'com.squareup.retrofit2:retrofit:2.0.2'
implementation 'com.basgeekball:awesome-validation:4.1'
implementation 'com.squareup.retrofit2:converter-gson:2.0.2'
implementation 'com.squareup.okhttp3:logging-interceptor:3.8.0'
}
Note: Each drawable is used only once.
The following thread does not solve my problem:
Drawable already belongs to another owner but does not expose a constant state
Problem found: The following attribute is causing the exception:
android:backgroundTint="#000"
If I don't use it, there is a pink background on the FAB :(
Fixed:
Added xmlns:app="http://schemas.android.com/apk/res-auto" in top layout
Used app:backgroundTint="#color/colorFABTint" instead of android:backgroundTint="#000"
Added following line in colors.xml
<color name="colorFABTint">#000000</color>
Resultant xml:
<RelativeLayout
android:layout_margin="30dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.design.widget.FloatingActionButton
android:layout_marginBottom="5dp"
app:layout_anchorGravity="bottom"
android:layout_width="wrap_content"
android:layout_gravity="bottom|end"
android:layout_height="wrap_content"
android:src="#drawable/ic_home_account"
app:backgroundTint="#color/colorFABTint"
android:id="#+id/fbtn_activity_main_account_manage_addresses"
app:layout_anchor="#id/fbtn_activity_main_account_edit_account"/>
Drawable has a state, and if you assign it to more than one Floating Action Button, then there will be a problem keeping track of the Drawable's state.
Maybe there is better solutions but one solution may be to set fab icons in onCreate instead of layout you can remove fab src from layout and use this:
fab.setImageResource(getResources().getDrawable(R.drawable.ic_edit_account).mutate());
or maybe this:
fab.setImageResource(getResources().getDrawable(R.drawable.ic_edit_account).getConstantState().newDrawable());
I work on an old Android project, I use a compileSdkVersion 16. I have put a SeekBar (a slider) in a dropdown menu. It works perfectly but my button, for displaying the dropdown menu is on the left and I want it on the right, like a parameter button in the Navigation Drawer Activity (the 3 vertically dot).
In my main activity I have thise :
ActionBar actionBar = getActionBar();
DropDown dropDown = new DropDown(this,"Controls","Power", "Tag Filter");
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
actionBar.setListNavigationCallbacks(dropDown, this);
I use two layout, one for the button in the action bar :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="end">
<TextView android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Controls"
android:textColor="#FFFFFF"
android:textSize="20sp" />
</LinearLayout>
An another one for my dropdown menu :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/seekBarTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="15dp"
android:layout_marginTop="15dp"
android:text="TextView"
android:textColor="#FFFFFF" />
<SeekBar
android:id="#+id/seekBar"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="11dp"
android:layout_toRightOf="#+id/seekBarTextView"
android:layout_weight="1" />
</LinearLayout>
[...]
</RelativeLayout>
I don't know how to put my button to the right, actually it's on the left, near the application name and I want to put it on the opposite.
I have this :
But I want this :
Edit :
My gradle file :
apply plugin: 'com.android.application'
def AAVersion = "4.3.0" // change this to your desired version, for example the latest stable: 4.2.0
android {
compileSdkVersion 16
buildToolsVersion '25.0.0'
//buildToolsVersion '25.3.1'
defaultConfig {
applicationId "com.company.dpdencoder.uhu"
minSdkVersion 14
targetSdkVersion 15
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
annotationProcessor "org.androidannotations:androidannotations:$AAVersion"
compile "org.androidannotations:androidannotations-api:$AAVersion"
compile 'com.android.support:support-v4:18.0.0'
compile 'com.google.guava:guava:15.0'
compile files('libs/jdom.jar')
// For Hexa coding/décoding
compile 'commons-codec:commons-codec:1.10'
compile files('libs/OpenApi_1.1.2.61_Common.jar')
compile files('libs/OpenApi_1.1.2.61_IaM.jar')
compile files('libs/OpenApi_1.1.2.61_IoT.jar')
}
Toolbar is advanced version of ActionBar. Use Toolbar instead of ActionBar.
Customize the Toolbar as your wish. And set it as ActionBar.
Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
setSupportActionBar(myToolbar);
Don't forget to use Theme.AppCompat.Light.NoActionBar theme as your activity theme.
More info about Toolbar: https://developer.android.com/reference/android/widget/Toolbar.html
for round about 2 weeks from now, I receive an error message, whenever I try to preview an .xml design-file in my Android Studio Project. As I am relatively new to the whole topic I'd like to ask whether you have an answer.
The error message:
Rendering Problems:
The following classes could not be found:
- android.support.v7.widget.Toolbar
OR
Rendering Problems:
The following classes could not be found:
- android.support.v7.widget.CardView
One of the .xml files:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/toolbar_tabs"
android:background="#color/primaryColor"
app:contentInsetStart="0dp"
app:contentInsetEnd="0dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="56dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="VPlan App RC1"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/white"
android:textSize="20sp"
android:layout_marginLeft="16dp"
android:fontFamily="sans-serif-medium"
android:id="#+id/textView7"
android:layout_marginStart="16dp"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="16dp"
android:layout_marginTop="16dp"
android:layout_centerHorizontal="true"
android:src="#drawable/ic_refresh"
android:id="#+id/ic_refresh"/>
</RelativeLayout>
<com.astuetz.PagerSlidingTabStrip
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#color/primaryColor"
android:textColorPrimary="#color/white"
android:textSize="14sp"
android:id="#+id/tabs"
android:layout_marginTop="?attr/actionBarSize" />
</RelativeLayout>
</android.support.v7.widget.Toolbar>
Also as it might help, here's the build.gradle file where the support library is located.
The build.grade file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion '22.0.1'
defaultConfig {
applicationId 'com.nocomment.vplanehs'
minSdkVersion 10
targetSdkVersion 22
versionCode 16
versionName '0.8.5_RC1'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(':volley')
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:cardview-v7:22.1.1'
compile 'com.android.support:recyclerview-v7:22.1.1'
compile 'com.android.support:support-v4:22.2.1'
compile 'com.jpardogo.materialtabstrip:library:1.0.9'
}
In this project we also use volley as well as libraries from ZXing's QR Code reader.
I'd be very thankful if someone could help me. Thank you in advance!