SearchView in AppCompat distorts icon - android

I am stuck in a very weird situation, my SearchView is working perfectly.
I just need to use OnActionExpandListener and for that purpose,
I have to set app:showAsAction="ifRoom|collapseActionView"
in my SearchView item in menu layout.
What it does is, it distorts my SearchView icon.
If I use app:showAsAction="always", OnActionExpandListener stops working but icon is shown perfectly.
Any kind of help is this regard will be highly appreciated, thanks.
Edit:
See the comments on the answer.

I agree, they have failed doing this nicely.
Anyway, I use this instead in order to detect when SearchView is being expanded/closed.
searchView.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {
#Override
public void onViewAttachedToWindow(View v) {
// Opened
}
#Override
public void onViewDetachedFromWindow(View v) {
// Closed
}
});

Related

OnSuggestionClicked in FloatingSearchView not working in ari morty library

I'm trying to implement Floating Search View from this library: Floating Search View so everything working fine but when implementing this code
floatingSearchView.setOnSearchListener(new FloatingSearchView.OnSearchListener() {
#Override
public void onSuggestionClicked(final SearchSuggestion searchSuggestion) {
Log.d("ssssssss", "clicked");
mLastQuery = searchSuggestion.getBody();
}
#Override
public void onSearchAction(String query) {
}
});
it's not working please help me.
after 6 hours i found the answer my mistake was in xml design so i put floating search view first child in coordinator layout so i change it to the last child and it worked perfectly

Android showcase focus tablayout

I'm using FancyShowCaseView library. When focusing on a button it work fine, but when focusing on TabLayout or MenuItem of Android SlidingTabs it don't work.
I'm tring to focus on TabLayout or MenuItem's of my app.
listen i have the same problem and add this:
view.getViewTreeObserver().addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
// Layout has happened here.
// Don't forget to remove your listener when you are done with it.
view.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
});
to my code and work fine.

How to load a layout inside another one on click and change button function?

I'm trying to do something like this:
When I go to this activity I have what is in black and some objects like EditText boxes.
Once I press the button I want those EditBoxes an other stuff that is up there to stay visible but unable to be edited (that's easy to do from code overriding onClick).
But at the same time I also want to load some layout down inside the same activity (from an xml) and change the button function to act over the objects of the new layout.
Could anyone give me an idea on how to do this two things staying in the same activity?
Update:
public void createButton(){
create_button.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
editText1.setEnabled(false);
editText2.setEnabled(false);
hidden_layout.setVisibility(View.VISIBLE);
create_button.setText("New text");
}
});
}
On the first click I want the button to do that. But once it's pressed I want it to do another thing. How could I do that?
(that's easy to do from code overriding onClick).
Actually I would recommend enable or disable which is easier to trace by using
view.setEnabled(bool);
as for the other question I'd recommend adding the layout from the start with setting visibility to GONE and when needed set the visibility to VISIBLE
view.setVisibility(View.VISIBLE);
view.setVisibility(View.GONE);
Ok, I've realized it was a dumb question, just add a flag an edit it:
public void createButton(){
create_button.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
if (!button_pressed) {
editText1.setEnabled(false);
edittext2.setEnabled(false);
hidden_layout.setVisibility(View.VISIBLE);
create_button.setText("New text");
button_pressed=true;
}
else{
create_button.setText("Second click");
create_button.setEnabled(false);
}
}
});
}
}

FAB transparent layer does not block the parent layer

I have a problem using Clans FloatingActionButton. I need to add a transparent layer that blocks the parent layer. The effect that I need is similar to Google Inbox.
So in my example I have this sequence:
1) Click item 3
2) Click on fab
3) When I click over transparent layer, the item from ListView is clicked.
I try to block the click event transparent layer using:
final FloatingActionMenu menu1 = (FloatingActionMenu) findViewById(R.id.menu1);
menu1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
menu1.close(true);
}
});
So with this code, when I click transparent layer the fab menu is closed (this is ok), but the same click listener blocking the click event over listView.
I have tried different ways to solve this problem but the only way I found was to resize the background programmatically . This is not a good solution because the effect is not good.
In a few hours I'll upload a demo and source code to github , but even as hope someone can help me with some idea. Thank You
EDITED
Here is the LINK to my repo.
Here is the LINK to download this apk
Here is the LINK to video demo
I have download your project from Github and tried the code myself and have solved the issue.
It is working perfectly for me as demonstrated in the Inbox by Google app. You just need to change a very small portion of your code.
menu1.setOnMenuToggleListener(new FloatingActionMenu.OnMenuToggleListener() {
#Override
public void onMenuToggle(boolean opened) {
if (opened) {
menu1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
menu1.close(true);
menu1.setClickable(false);
}
});
} else {
Toast.makeText(getApplicationContext(), "Close", Toast.LENGTH_SHORT).show();
}
}
});
Hope I could help you.

How to detect a click anywhere on a SearchView

How to detect a click on searchView?
I have tried using setOnClickListener, setOnSearchClickListener, setOnFocusChangedListener, but to no avail.
The problem seems to be only click on textbox. If I click anywhere outside of textbox onClickListener triggers, but not if click inside the textbox.
The problem that I am trying to solve is that I need to close a if user clicks anywhere. But I dont know how to handle the SearchView.
I have managed to find a way to solve my problem.
It's a bit hackish, but it works. You have to get the editText from searchView and set OnClickListener to it
int id = searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
EditText editText = (EditText) searchView.findViewById(id);
editText.setOnClickListener(listener);
Try this:
searchView = (SearchView)findViewById(R.id.searchView);
searchView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
searchView.setIconified(false);
}
});
Try adding app:iconifiedByDefault="false" to the SearchView tag in your layout XML.
An answer from a similar question: How to detect if SearchView is expanded?
searchView.setOnQueryTextFocusChangeListener { _ , hasFocus ->
if (hasFocus) {
// searchView expanded
} else {
// searchView not expanded
}
}

Categories

Resources