Reputation: 2166
I added a simple widget button to my Android activity:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:theme="@style/Theme.AppCompat"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="4sp"
android:layout_marginTop="1sp"
android:layout_marginRight="4sp"
android:orientation="vertical">
<ListView
android:id="@+id/orders_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:focusable="auto" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:src="@drawable/ic_add"
android:contentDescription="fazer pedido"
android:layout_margin="16dp" />
</LinearLayout>
Then I get
android.view.InflateException: Binary XML file line #18: Binary XML file line #18: Error inflating class android.support.design.widget.FloatingActionButton
Here are my gradle dependencies
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.squareup.okhttp3:okhttp:3.12.1'
implementation 'org.json:json:20190722'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.10.1'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}
I tried all solutions here on stackoverflow. Some mentions using backgroundTint but I don't even use that. Some others mention about v7 compact library, but I'm using androidx one. So this problem looks like a new one, different from others
Don't know if it helps but this is my activity:
public class OrdersActivity extends AppCompatActivity implements AbsListView.OnScrollListener{
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_orders);
Upvotes: 0
Views: 4854
Reputation: 176
You should use a Floating Button from the Google library. In order to do it, you must first add the library in your dependencies file. Here's the line of code :
implementation "com.google.android.material:material:1.2.0-alpha3"
Then, in your XML file, replace :
<android.support.design.widget.FloatingActionButton
with
<com.google.android.material.floatingactionbutton.FloatingActionButton
Upvotes: 7