I have 2 separate android studio projects, the first one is a chatting app that i developed and the second one is a shopping app that my friend developed. Now i want to create a button on the home screen that says "SHOP" and whenever it' s clicked i want the user to be taken to the shopping activity. The problem is i don't know if it' s possible to do that.
CodePudding user response:
To create a button first do the following
Open you Home Activity XMl fle in android studio and add button widget like below
<Button android:text="SHOP" android:background="#009688" android:layout_width="wrap_content" android:textColor="#FFFFFF" android:layout_height="51dp" android:id="@ id/shop" android:paddingLeft="5dp" android:paddingRight="5dp" app:layout_constraintTop_toBottomOf="parent" android:layout_marginTop="40dp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintHorizontal_bias="0.498" tools:ignore="TextContrastCheck" / >
note: you can tweak the button styles to your taste
Then go to you Java home activity and bind the button widget to enable you call onClickListener() method like below
Button button = (Button) findViewById(R.id.shop); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { //here intent is used to open the new activity Intent intent = new Intent(homeScreenActivity.this, ShoppingActivity.class); startActivity(intent); } });
You can also read about intent using the link https://developer.android.com/reference/android/content/Intent