setBackgroundColor is crashing the android application - java

I recently made a small app that should change the background color & text of the application when a certain amount of money is generated (here 100000). However, whenever I go past 10000, the application crashes. I am not sure why and can not get around it. I saw that this problem is with background color only because it is otherwise displaying text correctly.
Here is the XML for activity_main
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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/Trial"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#EC5353"
tools:context=".MainActivity">
<TextView
android:id="#+id/Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="92dp"
android:gravity="center"
android:text="#string/Title"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/money"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="72dp"
android:text="#string/moneyPresent"
android:textSize="22sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/Title" />
<Button
android:id="#+id/moneyGenerator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="72dp"
android:background="#FFFFFF"
android:backgroundTint="#732424"
android:backgroundTintMode="multiply"
android:text="#string/generateMoneyButton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/money" />
<TextView
android:id="#+id/richTag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="60dp"
android:text="#string/grind_boi"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/moneyGenerator" />
</androidx.constraintlayout.widget.ConstraintLayout>
Here is my Java Code (Omitted the packages as it would take a lot of space. Do tell me if anyone wants to read it.)
public class MainActivity extends AppCompatActivity {
private Button makeMoney;
private int totalMoney=0;
private TextView moneyText;
private TextView richAlert;
private ConstraintLayout background;
NumberFormat currency=NumberFormat.getCurrencyInstance(new Locale("en","in"));
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
makeMoney = findViewById(R.id.moneyGenerator);
moneyText=findViewById(R.id.money);
richAlert=findViewById(R.id.richTag);
makeMoney.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
totalMoney+=1000;
moneyText.setText(currency.format(totalMoney));
Log.d("MoneyTag", "Money Made: "+totalMoney);
Toast.makeText(getApplicationContext(),"Total Money= \u20B9"+totalMoney,Toast.LENGTH_LONG)
.show();
if(totalMoney>=10000) {
richAlert.setText("Welcome to moneyland bro 😁");
background.setBackgroundColor(16776960);
}
}
});
}
}

makeMoney = findViewById(R.id.moneyGenerator);
moneyText=findViewById(R.id.money);
richAlert=findViewById(R.id.richTag);
You're finding all the views, except background(ConstraintLayout), that's why it is throwing NullPointerException (Most likely, because you haven't attached logs).
You need to find the layout first
background = findViewById(R.id.Trial);
in onCreate.

you haven't defined "background" view in the above.
to use .setBackgroundColor you need to use it with some view
try making object of layout view then change the color of that layout
mConstraintLayout =
(ConstraintLayout)findViewById(R.id.Trial);
makeMoney = findViewById(R.id.moneyGenerator);
moneyText=findViewById(R.id.money);
richAlert=findViewById(R.id.richTag);
if(totalMoney>=10000) {
richAlert.setText("Welcome to moneyland bro 😁");
mConstraintLayout.setBackgroundColor(ContextCompat.getColor(this, R.color.yellow));

background = findViewById(R.id.Trial);
just find layout and null pointer excpetion will removed

Related

Keyboard hides BottomSheetDialog

I was using BottomSheetDialog for taking some input from the customer, my view contains TextInputLayout and button below the TextInputLayout when the user clicks on TextInputLayout the below button is getting hide by keyboard, so I need to that button above the keyboard, tried many possibilities but not able to fix it.
Attaching the pics regarding it.
Java file(activity) code:
BottomSheetDialog customTipAmountBottomSheetDialog;
private void showCustomTipAmountBottomSheet() {
customTipAmountBottomSheetDialog = new BottomSheetDialog(OrderActivity.this);
View customTipAmountBottomSheetView = getLayoutInflater().inflate(R.layout.custom_tip_amount_bottom_sheet, null);
customTipAmountBottomSheetDialog.setContentView(customTipAmountBottomSheetView);
InputMethodManager imm = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
assert imm != null;
imm.showSoftInput(binding.invoiceDialog.submit, InputMethodManager.RESULT_HIDDEN);
TextInputLayout customTipAmountBSTIL = customTipAmountBottomSheetView.findViewById(R.id.customTipAmountBSTIL);
EditText customTipAmountBSET = customTipAmountBottomSheetView.findViewById(R.id.customTipAmountBSET);
ImageView submit_custom_tip_amount = customTipAmountBottomSheetView.findViewById(R.id.submit_custom_tip_amount);
submit_custom_tip_amount.setOnClickListener(view -> {
String amount = customTipAmountBSET.getText().toString();
if (amount.length() > 0 && Integer.parseInt(amount) > 0) {
int tipAmount = Integer.parseInt(amount);
if (tipAmount > 0 && tipAmount < 51) {
binding.invoiceDialog.customTipAmountTv.setText(tipAmount);
captainTipAmount = tipAmount;
customTipAmountBottomSheetDialog.dismiss();
} else {
customTipAmountBSTIL.setError("Amount should be less than 50");
}
} else {
customTipAmountBSTIL.setError("Requires a valid amount");
}
});
customTipAmountBottomSheetDialog.show();
}
layout file custom_tip_amount_bottom_sheet.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
android:layout_height="match_parent">
<TextView
android:id="#+id/customTipAmountCaptainNameTv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:text="Tip amount for Rapido Captain"
android:textColor="#color/black"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.design.widget.TextInputLayout
android:id="#+id/customTipAmountBSTIL"
style="#style/Widget.MaterialComponents.TextInputLayout.FilledBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:hint="Enter amount"
app:boxBackgroundColor="#color/grey_100"
app:boxCornerRadiusTopEnd="8dp"
app:boxCornerRadiusTopStart="8dp"
app:errorEnabled="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/customTipAmountCaptainNameTv">
<EditText
android:id="#+id/customTipAmountBSET"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:digits="1234567890"
android:ems="2"
android:focusable="true"
android:imeOptions="actionDone"
android:inputType="phone" />
</android.support.design.widget.TextInputLayout>
<ImageView
android:id="#+id/submit_custom_tip_amount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="submitFeedbackConfirmationPopUp"
android:padding="#dimen/margin_8"
app:layout_constraintBottom_toBottomOf="#+id/customTipAmountBSTIL"
app:layout_constraintEnd_toEndOf="#+id/customTipAmountBSTIL"
app:layout_constraintTop_toTopOf="#+id/customTipAmountBSTIL"
app:srcCompat="#drawable/ic_arrow_forward_black_24dp" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:text="Button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/submit_custom_tip_amount" />
in Manifest file for activity file:
android:windowSoftInputMode="adjustPan"
Tried searching alot, but still not able to fix it. i got one answer related to my problem but it was with BottomSheetFragment()keyboard hides BottomSheetFragment, but i need with BottomSheetDialog. Please someone help me regarding this.
Let me know anything else info is required.
On onCreate() method in your activity java class use the below method.
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
Few days ago, i was faced same problem. Then using this portion of code into my onCreate() method, then the problem was solved.
Sample:
There are ways to achieve this:
1. Write below code into your Android Manifest file under <activity> tag:
android:windowSoftInputMode="stateHidden|adjustResize"
2. Write below code into your onCreate() method of activity:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
I hope its work for you.

Constraint layout admob issue

I am new to android programming and I do not know many things yet. What I am trying to achieve here is something like this. If the user does not have internet connection the ads dont show up or if the ads for some reason does not load then the ads dont show up. But the layout does remains the same meaning the ad space is left empty. What I did was warp the ad view in inside of a Relative Layout and then created a function which checks if the ads are loaded or not then changes the visibility of the layout, this seems to work and solve the blank space issues when ads does not load. But I think that this is not best way to do this and there must be a better way.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
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"
tools:context="com.example.admobTest.MainActivity"
tools:layout_editor_absoluteY="81dp">
<Button
android:id="#+id/btnExit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:text="#string/btnExit"
ads:layout_constraintBaseline_toBaselineOf="#+id/btnViewBuildProp"
ads:layout_constraintEnd_toEndOf="parent" />
<Button
android:id="#+id/btnViewBuildProp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="#string/btnViewBuildProp"
ads:layout_constraintBottom_toTopOf="#+id/relativeAdsLayout"
ads:layout_constraintStart_toStartOf="parent" />
/>
<TextView
android:id="#+id/txvStatus"
android:layout_width="368dp"
android:layout_height="0dp"
android:text="TextView"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp" />
<TextView
android:id="#+id/txvDeviceInfo"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="TextView"
ads:layout_constraintBottom_toTopOf="#+id/btnViewBuildProp"
ads:layout_constraintEnd_toEndOf="parent"
ads:layout_constraintStart_toStartOf="parent"
ads:layout_constraintTop_toBottomOf="#+id/txvStatus" />
<RelativeLayout
android:id="#+id/relativeAdsLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:visibility="gone"
ads:layout_constraintBottom_toBottomOf="parent"
ads:layout_constraintEnd_toEndOf="parent"
ads:layout_constraintStart_toStartOf="parent"
ads:layout_constraintTop_toBottomOf="#+id/btnExit">
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
ads:adSize="#string/adSize"
ads:adUnitId="#string/adUnitId"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:layout_editor_absoluteY="457dp" />
</RelativeLayout>
</android.support.constraint.ConstraintLayout>
MainActivity.java only relevant bits
public class MainActivity extends AppCompatActivity {
private AdView mAdView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
showAds(true); // this displays the ads
}
private void showAds(Boolean doShowAds) {
RelativeLayout relativeAdsLayout = findViewById(R.id.relativeAdsLayout);
if (doShowAds.equals(true)) {
mAdView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
relativeAdsLayout.setVisibility(View.VISIBLE);
} else if (doShowAds.equals(false)) {
relativeAdsLayout.setVisibility(View.GONE);
}
} //end showAds
} //end class
Don't add the AdView at all if the user has no internet connection.
Also an ad request should be avoided, if you know the user has no proper internet connection.
If the ad request fails you could remove the AdView from the Layout or try an other add request as often as you want.
You might also add some progress or an other background view (or image, progress etc.), wile the ad loads or if the user has no internet

Android Studio Buttons not Displaying

I made this dialog for my app that shows up allows you to delete the items from db. It used to be a textView and a button which called the function, all in a linear layout, which worked good. Now I changed to a Relative Layout so I could add another button on the same line as the other, I also added an editText.
My problem is that since I added those objects I am not able to see the buttons anymore. the editText and textView are visible.
XML Code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/dialog_deletefood"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.paulcosma.app2.SecondActivity">
<TextView
android:text="TextView"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/lblFoodDetails"
android:textAlignment="center"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="19dp" />
<Button
android:text="Şterge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/btnDeleteEatenFood"
android:layout_alignBaseline="#+id/btnModifyEatenFood"
android:layout_alignBottom="#+id/btnModifyEatenFood"
android:layout_toStartOf="#+id/lblFoodDetails"
android:visibility="visible" />
<Button
android:layout_marginTop="100dp"
android:text="Modifică"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/btnModifyEatenFood"
android:layout_below="#+id/lblFoodDetails"
android:layout_toEndOf="#+id/lblFoodDetails"
android:visibility="visible" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:id="#+id/txtEditValue"
android:maxLength="6"
style="#style/Widget.AppCompat.AutoCompleteTextView"
android:maxLines="1"
android:textAppearance="#style/TextAppearance.AppCompat"
android:fontFamily="sans-serif"
android:textSize="14sp"
android:textAlignment="center"
android:textColorLink="#android:color/holo_blue_light"
android:inputType="numberDecimal"
android:layout_marginTop="21dp"
android:layout_below="#+id/lblFoodDetails"
android:layout_centerHorizontal="true" />
</RelativeLayout>
This dialog is supposed to show on listView item click. Below is the code I used to show it.
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
HashMap<String, String> hmap = (HashMap<String, String>)parent.getItemAtPosition(position);
final String _name = hmap.get("food");
final int _id = foodDB.getFoodId(_name);
AlertDialog.Builder mBuiler = new AlertDialog.Builder(SecondActivity.this);
View mView = getLayoutInflater().inflate(R.layout.dialog_deletefood,null);
final TextView lblFoodDetails = (TextView) mView.findViewById(R.id.lblFoodDetails);
final Button btnDeleteEatenFood = (Button) mView.findViewById(R.id.btnDeleteEatenFood);
lblFoodDetails.setText("Aţi ales produsul " + _name + ". Aici puteţi adăuga sau scădea cantitatea printr-o anumită valoare sau puteţi şterge apariţia produsului.");
mBuiler.setView(mView);
final AlertDialog dialog = mBuiler.create();
btnDeleteEatenFood.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
foodDB.deleteEatenFood(_id);
Toast.makeText(SecondActivity.this,_name+" a fost sters",Toast.LENGTH_SHORT).show();
dialog.dismiss();
updateFoodList(foodDB.getAllEatenFood());
}
});
dialog.show();
}
This layout file renders the buttons in the Android layout designer as described (see below)
The problem may reside in code.
The problem was that both buttons where placed based on textView's size. When it changed, buttons got placed out of the screen
Bug:
android:layout_toEndOf="#+id/lblFoodDetails"
android:layout_toEStartOf="#+id/lblFoodDetails"

Android custom fonts Lollipop

I have two TextView which I want to put a custom font on.
In the OnCreate of my MainActivity, after the setContentView call, I wrote the following code:
Typeface myTypeface = Typeface.createFromAsset(getAssets(), "fonts/BernerBasisschrift1.ttf");
TextView welcomeTextView = (TextView)findViewById(R.id.welcome_message);
TextView introTextView = (TextView)findViewById(R.id.introduction_message);
welcomeTextView.setTypeface(myTypeface);
introTextView.setTypeface(myTypeface);
But for some reason, the font stays default.
The app runs on Galaxy S6 Edge device (Lollipop 5.0.2).
I read here that there's a problem with custom fonts on Lollipop, and in order to fix it I converted my font with the tool provided in the thread to ttx and vice versa, but even this didn't help.
Any ideas what can I do?
Edit:
Tested on Jellybean (4.3), not working either.
Another edit:
It works on a clean new project! Cant figure out the difference.
Putting the MainActivity and its' XML for help:
public class MainActivity extends FragmentActivity {
private LoginFragment loginFragment;
private TextView welcomeTextView;
private TextView introTextView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
hideActionBar();
setContentView(R.layout.activity_main);
welcomeTextView = (TextView)findViewById(R.id.welcome_message);
introTextView = (TextView)findViewById(R.id.introduction_message);
Typeface myTypeface = Typeface.createFromAsset(getAssets(), "fonts/BernerBasisschrift1.ttf");
welcomeTextView.setTypeface(myTypeface);
introTextView.setTypeface(myTypeface);
if (savedInstanceState == null) {
// Add the fragment on initial activity setup
loginFragment = new LoginFragment();
getSupportFragmentManager().beginTransaction()
.add(android.R.id.content, loginFragment, "facebookFragment").commit();
}
}
#Override
public void onWindowFocusChanged(boolean hasFocus) {
if(hasFocus){
// get all views on screen
ArrayList<View> views = new ArrayList<View>()
{{
add(findViewById(R.id.welcome_message));
add(findViewById(R.id.introduction_message));
add(findViewById(R.id.below_login));
add(findViewById(R.id.above_login));
add(findViewById(R.id.authButton));
add(findViewById(R.id.logo));
}};
// set animations
for(View view : views)
YoYo.with(Techniques.Tada).duration(700).playOn(view);
}
}
#TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void hideActionBar(){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
getActionBar().hide();
}
And the activity's XML:
<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="#drawable/main_background">
<ImageView
android:id="#+id/logo"
android:layout_width="256dp"
android:layout_height="101dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:background="#drawable/logo" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp">
<TextView
android:id="#+id/welcome_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="#string/welcome_message"
android:textColor="#color/White"
android:textSize="25sp"
style="#style/ShadowStyleText"
android:gravity="center" />
<TextView
android:id="#+id/introduction_message"
android:layout_below="#+id/welcome_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="#string/introduction_message"
android:textColor="#color/White"
android:textSize="18sp"
android:gravity="center"
style="#style/ShadowStyleText"
android:layout_marginTop="5dp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/bottom_login_chunk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="50dp"
android:layout_marginStart="50dp"
android:layout_marginLeft="50dp"
android:layout_marginEnd="50dp"
android:layout_marginRight="50dp">
<TextView
android:id="#+id/above_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="#string/above_login_button"
android:textColor="#color/White"
android:textSize="18sp"
style="#style/ShadowStyleText"
android:gravity="center" />
<com.facebook.widget.LoginButton
android:id="#+id/authButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/above_login"
android:layout_centerHorizontal="true"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp" />
<TextView
android:id="#+id/below_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/authButton"
android:layout_centerHorizontal="true"
android:text="#string/below_login_button"
android:textColor="#color/White"
style="#style/ShadowStyleText"
android:textSize="14sp" />
</RelativeLayout>
</RelativeLayout>
Ok so I found out recently that the facebook login button caused the problem, since everything worked when it was commented out.
So basically to solve this problem use another method to show the button instead using support fragment manager; sdk docs has lots of examples.

Moving buttons with animation and changing their position afterwards

I am learning Java and Android SDK. I want to create a simple application that is swapping 2 buttons so the left one is moving to the place of right one and v.v. with simple animation. I have tried the ObjectAnimator because I have read that it is moving the views objects permanently. But it's not :-( The objects stays there I mean the left one on the right and v.v. but their getLeft(), getTop() values are the same, and after next animations starts the objects are returning to the start position immediately. I have read that the ObjectAnimator needs some additional function to work properly but in the documentation there is no example :-( I have tried to add the setTranslationX function but it hasn't worked. Could somebody provide me with some simple example of how to do this?
http://developer.android.com/guide/topics/graphics/prop-animation.html#object-animator
"The object property that you are animating must have a setter function (in camel case) in the form of set(). Because the ObjectAnimator automatically updates the property during animation, it must be able to access the property with this setter method. For example, if the property name is foo, you need to have a setFoo() method. If this setter method does not exist, you have three options:
Add the setter method to the class if you have the rights to do so.
Use a wrapper class that you have rights to change and have that wrapper receive the value with a valid setter method and forward it to the original object.
Use ValueAnimator instead."
Thanks in advance.
try this code:
public class ActivityStartup extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle("hello");
setContentView(R.layout.main);
SlidingMenu menu = new SlidingMenu(this);
menu.setMode(SlidingMenu.SLIDING_WINDOW);
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
menu.setBehindOffset(100);
menu.setFadeDegree(0.35f);
menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
View view = G.layoutInflater.inflate(R.layout.menu, null);
view.findViewById(R.id.layout_crop).setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(G.context, "Crop Clicked", Toast.LENGTH_SHORT).show();
}
});
view.findViewById(R.id.img_logo).setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent browserIntent = new Intent("android.intent.action.VIEW", Uri.parse("http://example.com"));
startActivity(browserIntent);
}
});
menu.setMenu(view);
}
}
public class G extends Application {
public static LayoutInflater layoutInflater;
public static Context context;
#Override
public void onCreate() {
super.onCreate();
layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
context = getApplicationContext();
}
}
main.xml is:
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/hello" />
menu.xml is:
<ImageView
android:id="#+id/img_logo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="8dip"
android:scaleType="centerInside"
android:src="#drawable/hlogo" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="2dip"
android:background="#00ff00"
android:src="#drawable/ic_launcher" />
<LinearLayout
android:id="#+id/layout_crop"
android:layout_width="match_parent"
android:layout_height="48dip"
android:gravity="center_vertical" >
<ImageView
android:id="#+id/ImageView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dip"
android:scaleType="centerInside"
android:src="#android:drawable/ic_menu_crop" />
<TextView
android:id="#+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Crop"
android:textColor="#000000" />
</LinearLayout>
<LinearLayout
android:id="#+id/layout_day"
android:layout_width="match_parent"
android:layout_height="48dip"
android:gravity="center_vertical" >
<ImageView
android:id="#+id/ImageView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dip"
android:scaleType="centerInside"
android:src="#android:drawable/ic_menu_day" />
<TextView
android:id="#+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Day"
android:textColor="#000000" />
</LinearLayout>
<LinearLayout
android:id="#+id/layout_delete"
android:layout_width="match_parent"
android:layout_height="48dip"
android:gravity="center_vertical" >
<ImageView
android:id="#+id/ImageView03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dip"
android:scaleType="centerInside"
android:src="#android:drawable/ic_menu_delete" />
<TextView
android:id="#+id/TextView03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Delete"
android:textColor="#000000" />
</LinearLayout>

Categories

Resources