I'm having trouble setting the background for my button. I tried setting it to
android:background="@drawable/mybutton_background"
but that caused an error, saying "String types not allowed"
referring to "@drawable/mybutton_background"
. It also caused another error causing me to lose my R.java
file and giving me the "R cannot be resolved into a variable error"
. I just gave up on the button and deleted the background, but the error remained after it was deleted. Well, that error is now gone and I now get a message that says Error parsing XML: duplicate attributes for one line of code, but once I delete that line, the error message moves on to another line! It's like Eclipse won't update to realize I deleted that line of code. I checked for updates and cleaned my project countless times, but I'm still getting the same error. Does anyone know what's up with my project?
My error log:
activity_main.xml: Paint.setShadowLayer is not supported.
activity_main.xml: Failed to convert @drawable/ into a drawable
activity_main.xml: Failed to convert android:background=" into a drawable
activity_main:
<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"
android:background="android:background=""
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:scaleType="fitCenter"
android:src="@drawable/ball01" />
<Button
android:background="@drawable/"
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/imageView1"
android:layout_alignLeft="@+id/imageView1"
android:layout_marginBottom="17dp"
android:background="@drawable/mybutton_background" <----- where I get the error
android:focusableInTouchMode="true"
android:text="Enlighten me!"
android:textColor="#3f0f7f"
android:textSize="32sp"
android:textStyle="bold|italic"
android:typeface="serif"
android:visibility="visible" />
<LinearLayout
android:layout_width="match_parent"0 android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:weightSum="1" >
<View
android:id="@+id/view1"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0.2" />
<TextView
android:id="@+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.6"
android:gravity="center_horizontal"
android:shadowColor="@android:color/white"
android:shadowRadius="10"
android:textSize="32sp" />
<View
android:id="@+id/view2"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0.2" />
</LinearLayout>
</RelativeLayout>
MainActivity.java:
package com.example.crystalball;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
public class MainActivity extends ActionBarActivity {
private CrystalBall mCrystalBall = new CrystalBall();
private TextView mAnswerLabel;
private Button mGetAnswerButton;
private ImageView mCrystallBallImage;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mAnswerLabel = (TextView) findViewById(R.id.textView1);
mGetAnswerButton = (Button) findViewById(R.id.button1);
mCrystallBallImage = (ImageView) findViewById(R.id.imageView1);
mGetAnswerButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String answer = mCrystalBall.getAnAnswer();
mAnswerLabel.setText(answer);
animateCrystalBall();
animateAnswer();
}
});
}
public void animateCrystalBall() {
mCrystallBallImage.setImageResource(R.drawable.ball_animation);
AnimationDrawable ballAnimation = (AnimationDrawable) mCrystallBallImage.getDrawable();
if (ballAnimation.isRunning()) {
ballAnimation.stop();
}
ballAnimation.start();
}
private void animateAnswer() {
AlphaAnimation fadeInAnimation = new AlphaAnimation(0, 1);
fadeInAnimation.setDuration(1500);
fadeInAnimation.setFillAfter(true);
mAnswerLabel.setAnimation(fadeInAnimation);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Thanks for anything you can contribute!
In my case this error was due to duplicate xmlns attributes inside layout. If you have something like this:
<?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="person"
type="com.abc.PersonEntity" />
</data>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
...
Remove the xmlns attribute from the second layout:
<LinearLayout
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With