How to make the start Snackbar message when you click on the menu? - snackbar

How to make the start Snackbar message when you click on the menu?
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case (R.id.reset):
number1.setText(null);
number2.setText(null);
//Snackbar.make(findViewById(android.R.id.content) , "Text", Snackbar.LENGTH_SHORT).setAction("Action", null).show();
break;
case (R.id.quit):
finish();
break;
}
return super.onOptionsItemSelected(item);
}
It does not react.

You can use the main activity view to display the SnackBar :
Snackbar.make(this.findViewById(android.R.id.content),
"FooBar", Snackbar.LENGTH_LONG).setAction("Action", null).show();

When you click on menu item you can do like this:
Snackbar.make(getWindow().getDecorView(), .....);
Remember you MUST pass View object in order to show snackbar

Related

Open web page on click at a button in a JetBrains Space chat message using Kotlin SDK

I have a simple chat bot that renders "on this day" facts based on Wikipedia.
As you can see, there's a button on my UI. I want that if the user taps on it, a new browser tab opens with given Wikipedia url.
Until now, I only see the possibility to send other messages using buttons and there action (PostMessageAction).
Do you have any tip on how to achieve my feature idea?
Code
private fun makeMessage(container: OnThisDay): ChatMessage {
return message {
...
section {
text("On this day (${container.date}) happened:")
container.happenings.reversed().forEach {
text(
size = MessageTextSize.SMALL,
content = "${it.year}:\n${it.description}",
)
controls {
wikipediaButton(it.wikipediaUrl) <-- BUTTON
}
divider()
}
}
}
}
private fun MessageControlGroupBuilder.wikipediaButton(urlString: String) {
val action = PostMessageAction("a", "b") <-- NO other action possible?
button("Open Wikipedia", action, MessageButtonStyle.SECONDARY)
}
Screenshot
You can use NavigateUrlAction for this. Here's an example:
message {
section {
controls {
button(
text = "Open Wikipedia",
style = MessageButtonStyle.PRIMARY,
action = NavigateUrlAction(
url = "https://wikipedia.org",
withBackUrl = false,
openInNewTab = true
)
)
}
}
}

How to hide stacklayout if user clicked somwhere else on screen

I createt ResourceDictionary in App.xaml file for application header.
In header I created two dropdowns menu (with stacklayouts and grids).
First is for some user informations and second one is for search.
By default these dropdown menus are hiden.
Max one may be visible if user click on user-icon or on search-icon.
So in HeaderViewModel I cratet these two methods:
private async void AccountInformationAsync()
{
var userService = await UserService.GetUserData();
Username = userService.Username;
DisplayName = userService.DisplayName;
Status = userService.Status;
Influence = userService.Influence;
MTP = userService.MTP;
VisibilityInformation = !VisibilityInformation;
if (VisibilityInformation == true)
{
VisibilitySearch = false;
}
}
private void Search()
{
VisibilitySearch = !VisibilitySearch;
if (VisibilitySearch == true)
{
VisibilityInformation = false;
}
}
This works fine... If user click on user-icon user info will show up and if user then click on serach-icon info will hide an search menu will show up.
So, my question is how to hide any of these menus if user click somewhere else on the screen?
You need to add an TapGestureRecognizer on the Main Layout View of the Page. And on the Tap of it you can use Command and Hide both the dropdown Menu.
private void HideDropDowns()
{
VisibilitySearch = false;
VisibilityInformation = false;
}
HideDropDowns should be the Method assigned to the Command in the TapGestureRecognizer.

Add a bottom menu for RecyclerView item

I have a recyclerview that will have an option button to the right, and I want to achieve something like the animation below:
I'm using this as my reference but I have some disconnects.
First I want to know if I can even do this because every thing I find on adding a menu to a recyclerview is adding a basic menu pop up, which is not what I want.
I also have some disconnect on accessing the menu from the viewholder, I can access it from my fragment but I'd think I'd need to call it from the viewholder so I have what row clicked to fire up the menu.
If I'm overthinking the implementation and there's a simpler approach, I'm open to hearing it.
Im not sure if I am understanding what you want, but if it is to have a button that exist in the row items of the recyclerview to pop up a drawer from the bottom of the screen whenever the button is clicked, then you should just use a normal drawer setup (Navigation Drawer, Create a navigation drawer) for the activity and have an OnClickListener added to the row buttons (which can be done in onCreateViewHolder() or the holder's constructor) that triggers the drawer to open by calling openDrawer(). Note to do the latter, you have to pass the navigation drawer (DrawerLayout) into the adapter via the adaptors constructor (which means your adapter needs something to store the DrawerLayout in).
So
public class CustomAdaptor extends RecyclerView.Adapter<CustomViewHolder>{
private Context mContext;
private int mLayoutResourceId;
private ArrayList<Item> items;
private DrawerLayout drawer;
public CustomAdaptor (Context context, int resource, ArrayList<Item> itemArray, DrawerLayout drawer) {
this.mContext = context;
this.mLayoutResourceId = resource;
this.items = itemArray;
this.drawer = drawer;
}
public CustomViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(mContext).inflate(mLayoutResourceId, parent, false);
final CustomViewHolder holder = new CustomViewHolder(view);
holder.mbutton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
//Check if drawer is null and if not then call
drawer.drawerOpen();
}
});
return holder;
}
}
where mButton is the button in the holder/row. Note I havent tested this so there might be somethings im forgetting.

Get button from dataview on tap in Sencha 2

In my Sencha Touch 2.4.1 application, I have a dataview where each row has some text, and two buttons.
In my dataview, I have the following listener:
listeners: {
itemtap: function(dataview, index, target, record, e) {
// for testing
var el = Ext.fly(target);
var el2 = e.getTarget(null, null, true);
}
}
What I want to do is get the element that was tapped, and if it's a button, get that specific button and do something with it (like change its background color).
How can I get the specific button?
I have tried functions here and have tried to get the id and html of the element, but I've had no luck - usually the value or function is undefined. Tried e.target, el.dom...
How can I get the id, itemId, or cls of the button that was clicked?
You should use e.getTarget. For example, if your button has class "ux-dataview-button" then itemTap should be like this:
itemtap: function(dataview, index, target, record, e) {
if (e.getTarget('.ux-dataview-button')) {
// your code
} else {
// your code
}
}

define an event for custom android toast

I've made a custom android toast and tried to define on click listener event for the textview, but it doesn't work....any help??
LayoutInflater inflater = LayoutInflater.from(cntxt);
View layout = inflater.inflate(R.layout.toast_layout,null);
TextView text = (TextView) layout.findViewById(R.id.text);
text.setText(msg);
Toast toast = new Toast(cntxt);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
text.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method s'tub
//didn't go here???
toast.cancel();
}
});
toast.show();
Unfortunately, a Toast and any child child views of a Toast cannot receive touch input. You will have to create a custom View that mimics a Toast and attach that View to a layout.