Issue
The Android Application crashes after I use ImageButtons, previously I used drawable shapes and it was working fine.
activity_app_list.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.smartcarassistant.AppListActivity">
<TextView
android:id="@+id/appListTextview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:gravity="center"
android:text="Let me Assist You..."
android:textColor="@color/common_google_signin_btn_text_light"
android:textSize="20sp"
android:textStyle="bold" />
<LinearLayout
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="130dp"
android:gravity="center">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center">
<ImageButton
android:contentDescription="Travel With Weather"
android:id="@+id/buttonNotification"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@drawable/circle_background"
android:fontFamily="@font/cherry_cream_soda"
android:src="@drawable/notifications"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/buttonNotification"
android:layout_centerInParent="true"
android:clickable="false"
android:text="Manage">
</TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="14dp"
android:layout_below="@id/buttonNotification"
android:layout_centerInParent="true"
android:clickable="false"
android:text="Notifications">
</TextView>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center">
<ImageButton
android:contentDescription="Travel With Weather"
android:id="@+id/buttonMonthlyExpenses"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginLeft="8dp"
android:background="@drawable/circle_background"
android:src="@drawable/expense"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/buttonMonthlyExpenses"
android:layout_centerInParent="true"
android:clickable="false"
android:text="Monthly Expense">
</TextView>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center">
<ImageButton
android:contentDescription="Travel With Weather"
android:id="@+id/buttonMoodyMusicPlayer"
android:layout_width="100dp"
android:layout_marginLeft="5dp"
android:layout_height="100dp"
android:background="@drawable/circle_background"
android:src="@drawable/music"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/buttonMoodyMusicPlayer"
android:layout_centerInParent="true"
android:clickable="false"
android:text="Moody Music">
</TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="14dp"
android:layout_below="@id/buttonMoodyMusicPlayer"
android:layout_centerInParent="true"
android:clickable="false"
android:text="Player">
</TextView>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="130dp"
android:layout_marginTop="15dp"
android:gravity="center"
android:layout_marginStart="10dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center">
<ImageButton
android:contentDescription="Travel With Weather"
android:id="@+id/buttonMileage"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@drawable/circle_background"
android:src="@drawable/mileage"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/buttonMileage"
android:layout_centerInParent="true"
android:clickable="false"
android:text="Mileage">
</TextView>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center">
<ImageButton
android:id="@+id/buttonTravelWithWeather"
android:layout_width="100dp"
android:layout_marginStart="5dp"
android:layout_height="100dp"
android:background="@drawable/circle_background"
android:contentDescription="Travel With Weather"
android:src="@drawable/weather"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/buttonTravelWithWeather"
android:layout_centerInParent="true"
android:clickable="false"
android:text="Travel With">
</TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="14dp"
android:layout_below="@id/buttonTravelWithWeather"
android:layout_centerInParent="true"
android:clickable="false"
android:text="Weather">
</TextView>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center">
<ImageButton
android:contentDescription="Travel With Weather"
android:id="@+id/buttonHelpDesk"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@drawable/circle_background"
android:layout_marginLeft="10dp"
android:src="@drawable/helpdesk"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/buttonHelpDesk"
android:layout_centerInParent="true"
android:clickable="false"
android:text="HelpDesk">
</TextView>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="130dp"
android:gravity="center"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center">
<ImageButton
android:contentDescription="Travel With Weather"
android:id="@+id/buttonExploreAroundme"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@drawable/circle_background"
android:src="@drawable/explore"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/buttonExploreAroundme"
android:layout_centerInParent="true"
android:clickable="false"
android:text="Explore Around">
</TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="14dp"
android:layout_below="@id/buttonExploreAroundme"
android:layout_centerInParent="true"
android:clickable="false"
android:text="ME">
</TextView>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
AppListActivity.java
package com.smartcarassistant;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.Toast;
public class AppListActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_app_list);
final ImageButton btNotification=(ImageButton)findViewById(R.id.buttonNotification);
final ImageButton btMonthlyExpenses=(ImageButton)findViewById(R.id.buttonMonthlyExpenses);
btNotification.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent4=new Intent(AppListActivity.this,NotificationActivity.class);
startActivity(intent4);
}
});
btMonthlyExpenses.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent3=new Intent(AppListActivity.this,MonthlyExpensesActivity.class);
startActivity(intent3);
}
});
}
}
The code was fine as long as I was using shape backgrounds as icons for buttons, but when I switched to ImageButton
it crashes immediately after openeing.
Solution
The Problem was solved! I searched for it, and I got to know that some caches were responsible for it. After Cleaning the project, Invalidating Caches and restarting everything was fine.
Thank You all!
Answered By - Aniket Kodre
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.