I wanted to hide Contextual action bar in webview long press click. Is there any way to hide or disable it. I tried with below code:
webView.setOnLongClickListener(new View.OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
return true;
}
});
But I don't want to disable long press click. In short I want both long press to be working and CAB to be hide or disable in webview. Is it possible ? any solution welcome. Thanks
Want to hide or disable Contextual Action Bar looks like:
Related
Heyy,
I have implemented menu, where there are two menu items and when I click on first item, the other menu item goes disabled and vise-versa.
And when I click on back button navigation icon, I have to check if first item is disabled or not and if disabled, then turn the second item enabled, and if not then onBackPressed();
So, I don't know how to recognize which item is disabled.
Please help me fast.
There are some code references
This is my current try and it also have some errors. Please help me find another way or fix this code.
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (menu.getItem(0).getActionView().getVisibility() == View.VISIBLE) {
onBackPressed();
} else {
menu.getItem(1).setEnabled(false);
menu.getItem(1).setVisible(false);
menu.getItem(0).setEnabled(true);
menu.getItem(0).setVisible(true);
}
}
});
in onCreateOptionsMenu() store the menu into a local class field, and then to check if a certain menu item is enabled/disabled use isEnabled()
MenuItem item = menu.findItem(R.id.item_id);
if (item.isEnabled()) {
// enabled
} else {
// not enabled
}
Or you can use the order of the item among the menu items to get a particular item
MenuItem item = menu.getItem(0);
I am wondering how to animate going into and out of the contextual action mode. I am looking for an animation like in the app AwSms when you long press on a conversation (image provided, sorry for no video) The animation is essentially a ripple that comes from the middle and expands outwards on the Action Bar. I have searched long and far with no foreseeable way to animate the contextual action mode. It was definitely done here but I am not sure how. Thank you very much in advance!
Things I have tried:
public ActionMode.Callback iconEditCallback = new ActionMode.Callback() {
#Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
MenuInflater inflater = mode.getMenuInflater();
inflater.inflate(R.menu.menu_iconmanager_edit, menu);
mode.getCustomView().startAnimation(ripple);
return true;
}
I also tried:
getSupportActionBar.setShowHideAnimationEnabled(true);
I can't find anything on the google and stackoverflow so I had to ask.
I have menu on Toolbar:
<item
android:icon="#drawable/help_button_selector"
android:title="#string/Menu_Toolbar_Help"
android:id="#+id/MENU_HELP"
app:showAsAction="always"/>
When user long press icon, system shows tooltip (popup/context menu) with title. However on most devices it has black border (like in Toast). Is there any way to style this border/background? I have already created style for toolbar theme and popup, but I can't find a proper item name.
1.- You can follow this post to create your ToolTip link
2.-You can do this to show a Toast as a ToolTip, then you can customize it as you want.
view.setOnLongClickListener(new OnLongClickListener() {
public boolean onLongClick(View v) {
Toast.makeText(v.getContext(), "I'm a ToolTip", Toast.LENGTH_SHORT).show();
return true;
}
}
Hope it helps :)
Use below link to customize your Action Bar:
http://romannurik.github.io/AndroidAssetStudio/
open url -> GoTo Android Action Bar Style Generator -> Select the options -> click DOWNLOAD.ZIP -> Copy all the componets into their correspondence folders -> In your styles.xml file remove all the code and copy all the code of styles_**.xml file and delete this file.
Menu tooltip
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.menu_skip) {
View view = findViewById(R.id.menu_skip);
Tooltip.make(this, new Tooltip.Builder(101)
.anchor(view, Tooltip.Gravity.BOTTOM)
.closePolicy(mClosePolicy, 5000)
.text("Tooltip on a TabLayout child...Tooltip on a TabLayout child...")
.fadeDuration(200)
.fitToScreen(true)
.activateDelay(2000)
.withCallback(this)
.floatingAnimation(Tooltip.AnimationBuilder.DEFAULT)
.showDelay(400)
.build()
).show();
return true;
}
return super.onOptionsItemSelected(item);
}
Visit more
When you click button in my app if you are fast enough before the screen/popup loads it loads them multiple times. I know how to disable the click on the button but that's not an option, because when you close the popup or return to the previous screen the button is disabled. I tried with Handler and Runnable to wait for 1s before the button is active again but this solution is not optimal in case if the OS needs more time to open the next screen. So I am searching for the most optimal solution. Any ideas?
Edit: setClickable(false) and then setting it back to true doesn't work because it loads my screen/popup slower than expected the button is enabled again and it opens the screen/popup multiple times again.
You can disable the multiple click at the same time using the following code
private boolean isClicked;
#Override
public void onClick(final View v) {
if(isClicked) {
return;
}
isClicked = true;
v.postDelayed(new Runnable() {
#Override
public void run() {
isClicked = false;
}
}, 1000);
}
Implement logic in your onClick to determine whether you want to ignore the click.
You can disable the button. When you close the popup enable the button and when the popup is visible make it disable. Keep listening the actions for popup and when the user get back to the previous screen.
Maintain one variable on button onClick listener and change the value to determine when you want to click button..
You can stop multiple operations by this way.
button.setOnClickListener(new OnClickListener(){
#Override
public void onClick()
{
performOperation();
}
});
public void performOperation()
{
static boolean working = true;
if(working)
{
return;
}
working = true;
//Do you work here;
working = false;
}
Action Bar
I'm talking about the (Number 1, in the pic), button with a little arrow and the app icon and the top left side of the screen. It is automatically defined when we select the "Black activity" template.
My app has a pretty huge hierarchy graph, got about 25 activities now.
I'm basically just showing a few tutorials and one can navigate to it according to the categories.
Now that "Back" (?) button thingy on action bar is on every screen I have, and I do want to keep it. The code shows no error, but when I actually press that button, the app stops working.
What I want, is to just replicate the actual back button function with that (Number 1) button, that I showed in the image.
When I press it, the top most screen should close, and the last one should open. Just close the screen.
What I tried :
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
this is the the function that inflates that buggy button along with the action bar. I tried to replace the entire code, and call "Finish" function, but that failed miserably.
I was unable to find a function specifically made for that top left most button...
I want the top most screen on the stack(the one in the foreground) to close, when this button is touched.
How to do this ?
I think the easiest way out is follows:
I am assuming that from activity A you are starting the activity B. Now from activity B you want to go back to activity A on pressing the top left back button on action bar. simply call this.finish() or ActivityName.this.finish() from there:
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
this.finish();
return true;
}
return super.onOptionsItemSelected(item);
}
This should finish your current activity. However if you have lot of activities, then you might have to do this in all the activities. To save yourself from that effort, you can make a class lets call it AbstractActivity; that extends Activity. Then you can extend all your other activity classes to extend that class(AbstractActivity). Inside AbstractActivity you can put the above code. So now that piece of code would be valid for all your activities and that feature would be implemented for all of them. Basically this sort of thing (Inheritance)can be used any time, when there are some common features which would be applicable to your many classes.
If you are receiving any errors, please do post your LogCat if you require further help.
Hope this helps you.
just giving basic code given by #shobhit puri...
for invoking the action bar back button..add the following code in the onCreate() method along with the onOptionsItemSelected....
protected void onCreate(Bundle savedInstanceState)
{
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_information);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
this.finish();
return true;
}
return super.onOptionsItemSelected(item);
}