background image of android screen

Asked

Viewed 1,957 times

2

Good afternoon ! I am trying to put a background image in my application login screen, this image was downloaded from the site Unsplash, and when I put it in the background property of my layout the following error is presented:

        java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ramattecgmail.rafah.herdeirosapp/com.ramattecgmail.rafah.herdeirosapp.Activitys.LoginActivity}: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class <unknown>

follows XML code:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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:background="@drawable/bg"
tools:context="com.ramattecgmail.rafah.herdeirosapp.Activitys.LoginActivity">

   <Button
    android:id="@+id/bt_login_face"
    android:layout_width="@dimen/bt_login_width"
    android:layout_height="@dimen/bt_login_height"
    android:paddingTop="@dimen/bt_login_pad_vertical"
    android:paddingBottom="@dimen/bt_login_pad_vertical"
    android:paddingLeft="@dimen/bt_login_pad_horizontal"
    android:layout_marginBottom="@dimen/bt_login_face_mrg_bot"
    android:layout_gravity="center_horizontal|bottom"
    android:stateListAnimator="@null"
    android:elevation="12dp"
    android:background="@drawable/face_button_login"
    android:drawableLeft="@drawable/face_btn2"
    android:text="@string/login_face"
    android:textSize="@dimen/bt_login_txts"
    android:textAlignment="center"
    android:textColor="@color/primaryTextColor" />

<Button
    android:id="@+id/bt_login_google"
    android:layout_width="@dimen/bt_login_width"
    android:layout_height="@dimen/bt_login_height"
    android:paddingLeft="@dimen/bt_login_pad_horizontal"
    android:paddingBottom="@dimen/bt_login_pad_vertical"
    android:paddingTop="@dimen/bt_login_pad_vertical"
    android:layout_marginBottom="@dimen/bt_login_google_mrg_bot"
    android:layout_gravity="center_horizontal|bottom"
    android:stateListAnimator="@null"
    android:elevation="12dp"
    android:background="@drawable/google_button_login"
    android:drawableLeft="@drawable/google_btn"
    android:text="@string/login_google"
    android:textSize="@dimen/bt_login_txts"
    android:textAlignment="center"
    android:textColor="@color/red" />

 </FrameLayout>

Below follows the code of Activity:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);

    mAuth = FirebaseAuth.getInstance();

    /*************** TESTE DE LOGIN COM BOTÃO CUSTOMIZADO ***********/
    FacebookSdk.sdkInitialize(getApplicationContext());

    btFaceLogin = findViewById(R.id.bt_login_face);
    btGoogleLogin = findViewById(R.id.bt_login_google);

    //EVENTOS
    btGoogleLogin.setOnClickListener(this);
    btFaceLogin.setOnClickListener(this);

    callbackManager = CallbackManager.Factory.create();
    LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {
            Log.d(TAG, "Sucesso linha 82");
            AccessToken token  = AccessToken.getCurrentAccessToken();
            handleFacebookAccessToken(token);
        }

        @Override
        public void onCancel() {

        }

        @Override
        public void onError(FacebookException error) {

        }
    });

    /*************** TESTE DE LOGIN COM BOTÃO CUSTOMIZADO ***********/

    // Configure sign-in to request the user's ID, email address, and basic
    // profile. ID and basic profile are included in DEFAULT_SIGN_IN.
    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestIdToken(getString(R.string.default_web_client_id))
            .requestEmail()
            .build();

    // Build a GoogleApiClient with access to the Google Sign-In API and the
    // options specified by gso.
    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .build();

}

In setConentView the error is already shown, the image is in png format. By running the app this way it doesn’t even open.

  • can post the Activity code ? onCreate only

  • 1

    where the face button in XML?

  • Sorry, guys, I didn’t even know I had my face button off

2 answers

0


This error usually occurs when your android:background is very large. Do the test to decrease the image.

  • That’s right, the image I downloaded was too big, thank you very much for the tip !

-1

Try to put this in your xml:

<Button
   android:id="@+id/bt_login_face"
   android:layout_width="wrap_content"
   android:layout_height="@dimen/bt_login_height" />
  • Thanks for trying Felipe, but it’s not the missing button, I just forgot to leave it in the example code I posted

  • beauty! try to remake your code that can work.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.