How to make custom text selection dialogue in android - java

How to Highlight text in android TextView like this?
& also how to show a custom dialogue on text selection?
I Have Tried with TextView default property
android:enabled="true"
android:textIsSelectable="true"
android:focusable="true"
android:longClickable="true"
But By Using this it only show default share and copy option from android.

You can set the hilight by calling setSelection on the TextView. As for the dialog- you can add to it, but you can't remove from it. The way to add to it is to create an Activity with an intent filter that makes it catch the PROCESS_TEXT action. That will automatically make Android add your app to the copy paste bar with the name of your app, and allow users to click on it to perform whatever transformation you wish.
Please note that this will occur in every app, not just your own. I don't know of a way to make it specific to your app.
So for example the "Tweet" option on your bar there is because you have twitter installed. Delete it and the option would disappear. There's no other way, other than to totally turn off that menu and build your own version.

Related

How to add Search Dialog to an Android app

Here is my issue. I have a requirement to add a search dialog to an Android app. I have found the way to add a search view component, but not the search dialog. I know from the Android Developers docs that I am supposed to use onSearchRequested() to make it appear, but I don't quite understand what that means. Is the search dialog supposed to be tied to my own UI component that will invoke this method or am I missing something? I haven't managed to read all the docs on searching, but I was hoping someone may point me where I missed something important.
I am not well versed in Android development, only a few small projects. I am more of a Flutter dev when creating a mobile app, but I don't have the option this time around.
Below is the screenshot of what the Android Developers docs show as search dialog and the comparison to search view.
Based on the documentation, the steps for invoking a Search Dialog are:
create an Xml file (which you already did for search widget)
Declaring a searchable activity: create an actiivty and notify the Manifest that it gets the search results (you did that too)
3. At the Manifest, decalre some other activity (MainActivity for examlpe) to be able to invoke the search dialog. Add this line inside <activity> tag:
<meta-data android:name="android.app.default_searchable"
android:value=".SearchableActivity" />
(android:value is the name of the Activity that gets the searcg results, which you defined at step 2)
4. At that Activity, create a search button etc and invoke the Serach Dialog like this:
onSearchRequested();
Very simple actually :)
The search words stored in intent.getStringExtra(SearchManager.QUERY) as a String, you get it at onCreate() of SearchableActivity class. From this point you should handle the search query and results logic...

Java - Extra Window Button

Google Chrome Recently had an update that added an extra button onto to the top of the window that allowed you edit your account settings. I have a great use for an extra button like this one but I do not know how to make it. So, how can I add an extra button at the top of the window?
This is what I would like to do or have in mind.
This is more of an amateur/simple answer but it could be possible just to make a title bar with all of the drop downs without text until you reach the button you want and customize that

How would I add a Google Plus One button to the settings of an Android lwp?

How would I add a Google Plus One button to my Android live wallpapers settings like the following?
Well here is how I would do it, I haven't tested it just searched over Google.
You will have to use the Google Plus API, here you can see how to add +1 button to a layout in the accepted answer.
Now you know how to add +1 button, to add this to your preference screen you have to create a Preference item with a custom layout which is explained here. In this custom layout you put the previously created layout with the +1 button and then you add it to your Preference List.
Now you have a Preference item with a custom layout with a +1 button, just add an onClickListener to the Preference item with the +1 button and using Google Plus API do whatever you want when user clicks it!
Another way is to add Google Plus icon to the preference:
Create a Preference item and add Google Plus icon to it as described here.
Add an onClickListener to the Preference item and using Google Plus API do whatever you want when user clicks it.
Hope this can help you! Sorry for my bad English!

Way to successfully change Content View?

I have an app that uses this RibbonMenu and I wanted to know if it was possible to use the menu items to change the ContentView of the Activity instead of another activity to reduce the size of my app. I've tried doing this already,and it changed the content view perfectly, but i was not able to press the home button. I'm in a bit of a rush here, but i'll try to post code if anyone asks for it. thank you!
Menu items is UI element. It does nothing by itself. It however can trigger some more actions in your code. As for changing activity layout, yes, you can call setContentView() at any time you want.
to reduce the size of my app
this is not the way optimalizations should be done

Change app background

I'm currently making an android app in which I'd like the user to be able to change the background image.
I've got 3 images and a screen where I can choose a picture and a button for applying.
The issue:
I can allow the user to see all images in the way I want, but I don't know how to set the selected image as app background.
What I want to do:
I want the user to click a button, which exports the selected image to "bakgrund.png" in "/res/drawable-mdpi" and replaces the current one. This would allow me to easily integrate the background switcher. Renaming of current files also works.
PS: My current background images are located in /res/drawable-mdpi named 1.png 2.png and 3.png.
Easiest way would be to call the setBackgroundResource(image_id) method on the root layout. Like if you have a LinearLayout which has android:id="#+linear" as the root layout in the layout xml, then this code will help:-
LinearLayout linearLayout=(LinearLayout) findViewById(R.id.linear);
linear.setBackgroundResource(R.drawable.1);//call this in the OnClickListener's OnClick Method
Firstly, you need different themes which has different backgrounds. So you may use this.setTheme method in your Activity.
Indeed I suggest you, two different layout (with different backgrounds but have same components) and using setContentView during onClick.
I hope it solves your issue.

Categories

Resources