To remove the back arrow button from Action Bar - java

In my Android Project, whenever I go from First Activity to Second, I get an left arrow button followed by the some text in the action bar. That left arrow only comes when I set my First Activity as the hierarchical parent of the Second Activity.
I want to remove that back button and replace it with an icon. I have read other posts for the same question, and so I have already tried the following code in my onCreate() method.
getActionBar().setDisplayHomeAsUpEnabled(false);
But after reaching to the second activity, the app gets crashed.
Please help me out.

Use getSupportActionBar() bar:
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
getSupportActionBar().setHomeButtonEnabled(false);

getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_yourindicator);

Related

How to display text in a new activity when two radio buttons from two different activities are clicked?

I am using Java and Android Studio. I have one activity with a few options to select from, and once one of them is selected, they click the button that takes them to the next activity. They do the same thing again except this time when the user clicks the button it takes them to a new activity where it displays the results based on the two radio buttons clicked previously. How can I do this?
You can send some variable through intent and onCreate() method of the second activity, you can use that variable to differentiate your functionality.
This video demonstrates the functionality of the radio button: https://youtu.be/zJG9Prn3vZ0
In this video you can know how to pass arguments to another activity: https://youtu.be/OMCctaE66b8
Hope that helps you to solve your problem.
You cannot declare a method inside another method. Put a closing brace after onCreate.
When you are opening a new activity, you are doing it with an Intent. Put the values you want to send (bool clicked) the new activity inside the intent

How to enable back button of phone to go back to previous activity without enabling back button icon on action bar?

Suppose I move to another activity from my current one and then I need to go back to previous activity by pressing the back button originally present in the phone along with a home button and menu button. I have disabled my Action Bar and I don't want to enable it. Nor I want to create an icon in my activity that represents back.
Please Help!
to initiate the back operation you can call
super.onBackPressed();
from your activity.

Multiple tap and multiple navigation activity

Help me solve my problem. I'm doing the transition between the activity using the startActivity method.
If I press n-times on the button that initiates startActivity, there will be n-transitions to activity. How to make the transition was only one?
You can set the button unclickable when you press it the first time.
The code is:
button.setEnabled(false);

Perform function when WindowCloseOnTouchOutside

I've searched around for a while but I can't seem to find an answer to this. I have a theme for my Android application that closes an activity when the outside is clicked by using the XML script <item name="android:windowCloseOnTouchOutside">true</item>
However, I need a function to fire when this is done as it returns to the previous activity and passes information. onBackPressed() doesn't seem to pick this up and I can't find any information on what would.
RESULT
As far as I can uncover it's not possible to add information to the activity returned to OnActivityResult if you are using windowCloseOnTouchOutside as it directly uses onPause() with no break between.
My solution was to remake the popup window with a transparent surround that would be detected when the player clicks onto it. Then I created a function that is detected when the back button is pressed or the player clicks outside of the window

set the cursor to search view automatically

I have a button in an activity, on clicking that button, I direct the user to a search activity with a search view in the toolbar..
I'm using android.support.v7.widget.SearchView, I managed to expand it automatically using searchView.setIconifiedByDefault(false) in onCreateOptionsMenu..
I also open the keypad automatically in activity onCreate, yet I still have to click in the searchView to start typing there, I want the cursor to be set there automatically..
any help?
call setIconifiedByDefault(false) when the searchview is intialized.
Sets the default or resting state of the search field. If true, a single search icon is shown by default and expands to show the text field and other buttons when pressed. Also, if the default state is iconified, then it collapses to that state when the close button is pressed. Changes to this property will take effect immediately.
Try the below, it worked for me once.
searchView.setIconifiedByDefault(true);
searchView.setFocusable(true);
searchView.setIconified(false);
searchView.requestFocusFromTouch();
Update: If you are Using android.support.v7.widget.SearchView the behaviour is very different. clearFocus is needed if you don’t want the keyboard pop-up all the time.
Also in the searchview layout, use <requestFocus /> tag.

Categories