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
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 trying to display a popup edit text when "action_guess" is clicked. i am not sure on how to go about this. here is my code:
public MyMenuItemClickListener() {
}
#Override
public boolean onMenuItemClick(MenuItem menuItem) {
switch (menuItem.getItemId()) {
case R.id.action_guess:
Toast.makeText(mContext, "guess code", Toast.LENGTH_SHORT).show();
return true;
default:
}
return false;
}
If you want an EditText in a Dialog, you can follow this example.
https://www.mkyong.com/android/android-prompt-user-input-dialog-example/
If you want it appear in the ActionBar, you can overlay the EditText inside the ActionBar layout and show/hide with setVisibility().
Option Menu:
<item
android:id="#+id/home"
android:icon="#drawable/ic_home"
android:title="Home"/>
<item
android:id="#+id/companies"
android:icon="#drawable/ic_companies"
android:title="Companies"/>
<item
android:id="#+id/contact"
android:icon="#drawable/ic_contacts"
android:title="Contact"/>
I want to change this item's icon programmatically depending on the open Fragment and, obviously, have different actions when the user hits this button. I tried several things to do that, but nothing worked.
The last thing I tried was this code in my Fragment onCreateView method:
Menu menu = bottomNavigationView.getMenu();
menu.findItem(R.id.ic_home).setIcon(R.drawable.ic_home_fill);
but its not work for me.
what i tried in selectFragment(MenuItem item)
switch (item.getItemId()) {
case R.id.home:
item.setIcon(R.id.ic_home_fill);
break;
}
I want to change the icon of the bottom navigation of selected position. if user clicked one item then the icon change to another one and when i select another one then 1st icon can set as a default.
refer this link:Android: Bottom Navigation View - change icon of selected item
but it's not work for me
plz give me a other solution.
Thank you
Try this, It worked for me
BottomNavigationView mBottomNavigationView = (BottomNavigationView) findViewById(R.id.bottom_nav);
mBottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
#Override
public boolean onNavigationItemSelected(MenuItem item) {
invalidateOptionsMenu();
switch (item.getItemId()) {
case R.id.click_to_use:
addHomeFragment(MainActivity.this);
mTitle.setText("Home");
item.setIcon(R.drawable.device);
break;
case R.id.history:
addNotifyFragment(MainActivity.this);
mTitle.setText("History");
item.setIcon(R.drawable.ios_icon);
break;
case R.id.settings:
addSettingFragment(MainActivity.this);
mTitle.setText("Settings");
break;
}
return true;
}
});
after any modification in the menu, you would have to make an "Invalidateoptionsmenu ()" in the action. I invite you to want to test this feature . see here
I have a refresh icon on my menu which when clicked will refresh the contents of the Activity. But the problem is that the refresh icon is still clickable while it is refreshing which I do not want. Here is my menu.xml file
<menu 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"
tools:context=".MainActivity">
<item
android:id="#+id/action_refresh"
android:orderInCategory="100"
android:icon="#mipmap/ic_refresh"
android:enabled="true"
android:title="#string/action_settings"
app:showAsAction="always"/>
And here is where I handle the click event for the icon
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_refresh) {
// getData() fetches the data and updates the display
getData();
return true;
}
return super.onOptionsItemSelected(item);
}
Also, is there a way to maybe dim the icon so that the user knows that they have already clicked the icon?
When you click the icon, use the isEnabled() method of your Menuitem to check if it is currently enabled. If it is, then disable it until the data is loaded. Once the data loads successfully, then you can enable it again. Example:
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if(item.isEnabled()) {
// "Dim" the icon like you said. You can use other alpha values if you like.
item.getIcon().setAlpha(130);
// Disable the menu icon
item.setEnabled(false);
}
getData();
return true;
}
return super.onOptionsItemSelected(item);
}
Now, you said that you have a getData() method which updates the display after it fetches the data. Once the data is fetched, check if the Menuitem is disabled. If it is disabled, then enable it again. Example:
if(item != null && item.isEnabled() == false) {
// "Undim" the icon
item.getIcon().setAlpha(255);
// Enable it again
item.setEnabled(true);
}
You can use setEnabled(true) method to enable/disable menu item
You could create a second menu.xml, that is used after the refresh button is clicked. To force a menu redraw call invalidateOptionsMenu();
In this second menu.xml, the refresh button could be disabled, or switched to a diffrent one, indicating the user, that the refresh is on going.
Easiest way to fix this is to hold on to the menu item in your activity.
private MenuItem mRefreshItem;
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater infl = new MenuInflater(this);
infl.inflate(R.menu.menu, menu);
mRefreshItem = menu.findItem(R.id.action_refresh);
return super.onCreateOptionsMenu(menu);
}
/** Call this when you begin or end loading */
private void setRefreshEnabled(boolean enabled) {
mRefreshItem.setEnabled(enabled);
}
I am working on an app, in which I am want to use a pop-up menu to control some actions and settings. However, when I launch the app in my emulator, the items appear blank, although when I click on them, the action is fired and it works. Here is a screen of the emulator:
I am following the guide, so my code does not differ much from the dev guides, but here is my code:
#Override
public boolean onItemLongClick(AdapterView<?> parent, View view,
int position, long ID)
{
// TODO Auto-generated method stub
courseId = ID;
fields = sqldbase.query(DBHelper.courseTable, new String[] {
DBHelper.courseID, DBHelper.courseName,
DBHelper.courseProf, DBHelper.averageGrade },
DBHelper.courseID + " = " + ID, null, null, null, null);
PopupMenu popup = new PopupMenu(getBaseContext(), view);
popup.getMenuInflater().inflate(R.menu.courses_popup_menu,
popup.getMenu());
popup.show();
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener()
{
#Override
public boolean onMenuItemClick(MenuItem item)
{
Log.i(TAG,"OnMenuItemClick Fired"); return false;
}
});
return false;
}
});
Could this be related to a problem with themes? I have been trying to use a Holo.light.NoTitleBar theme, so in my xml in eclipse, the word Passbook does not show, and everything is white, instead of black. However, after running in the emulator, the theme is ignored, and this shows up.
Thanks.
fixed it. apparently, popup menus use the attribute android:title instead of android:text.