ActionBarSherlock - Share Content icon issue - java

I am using ActionBarSherlock and have implemented ShareActionProvider.
When a user selects an app to share content with, eg Twitter, the actionbar displays a Twitter icon next to the Share button icon. This stays there forever.
Does anybody know how to disable the application icon from appearing next to the Share button?

Found the answer:
Implement OnShareTargetSelectedListener and set it on the
ShareActionProvider
public void onCreateOptionsMenu(Menu menu){
....
actionProvider.setOnShareTargetSelectedListener(this);
....
#Override
public boolean onShareTargetSelected(ShareActionProvider source,
Intent intent) {
context.startActivity(intent);
// started activity ourself to prevent search history
return true;
}

The top target is featured in the action bar. This is the behavior of the widget as it exists in Android.
If you do not want this behavior copy the sources into your app and modify its behavior to never display the top target icon.

Related

can not click action bar app icon Android

I'm trying to make the action bar app icon (top left image) clickable but it just doesn't work, I've already searched for some answers but nothing works. I've already tried to getSupportActionBar().setHomeButtonEnabled(true); and I can see the icon, but i still can't click on it. I know I can handle the event in the method onOptionsItemSelected(MenuItem item) but the event will never get triggered with my situation. I also don't get why I have to use getSupportActionBar(); instead of getActionBar()...the second one is always null. The minimum sdk is 16 and the maximum is 22. I read this answer -> ActionBarCompat - App icon action (click) not working on 4.0 devices but I don't know how to get in the ActionBarHelperICS.java class or if it apply to my case.
You haven't really posted any code. But there may be 2 problems.
You have to specify which is the parent activity in your manifest file.
Under the activity's tag in manifest, you'll have to specify which activity your home button will point to. Something like this:
android:parentActivityName="com.example.app.MainActivity"
Or Override your onOptionsItemSelected
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
//add what you want to do here...
return true;
default:
return super.onOptionsItemSelected(item);
}
}

Android Application for Kids

I'm Developing Android Application for Parental Controlling, so I want to disable home and back button. Because kids are unpredictable, their can push home button or back button and so on. Than i want to disable sliding notification bar. (Because notification bar can change device configuration and setting)
I'm planning to create Android Application which is similar to the Samsung Kids Mode-Parental Control.
Is possible to create application like Samsung Kids Mode? Can you give some link/article or even example program to me?
I Have tried this :
#Override
public void onAttachedToWindow() {
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
super.onAttachedToWindow();
}
but it not handle home button, the Home button still working.
Thanks in advance to everyone for taking time to read this, hoping a positive solution.
I dont know of anyway to override the home button. Im not sure that it can be done. You can override the back button like so.
#Override
public void onBackPressed() {
//do nothing, important dont call super.onBackPressed
}
Another this you can do is set the app to immersive mode to reduce the chance of accidently exiting the app
https://developer.android.com/training/system-ui/immersive.html
Extended from Activity
#Override
public void onBackPressed() {
}
can be used to override back button. Be sure to remove super.onBackPressed().

How do I add a new page to an Android app?

Apologies for the basic question, but I can't really find the answer online. Possibly because I'm not sure what I need to be searching for!
I have created a simple one page app following a guide. At the top there is a menu button, under that 'Settings'. I want to make it so that when the Settings button is clicked it takes you to a new settings page and allows the user to change the background colour, font colour or something simple like that.
However, I can't work out how to actually create a new page. I tried creating a new class and linking the intent under the action_settings bit in the main .java file, but that didn't work for me.
Please could someone give me some guidance?
GitHub repo: https://github.com/LewisLebentz/Quoter
If the settings button is on the action bar then follow these steps:
1) Create a new activity by right-clicking on the Java folder > New > Activity > Blank Activity. This will automatically create a layout file and a Java class. It will also automatically register the activity in the manifest.
2) Next you want to go to the Quoter.java file. Add the following code to it.
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
// This code will start the new activity when the settings button is clicked on the bar at the top.
Intent intent = new Intent(Quoter.this, newActivityName.class);
startActivity(intent)
return true;
}
return super.onOptionsItemSelected(item);
}
That's it! When you click the settings button, it should start a new activity! Let me know if it does not work!
By the way, you can search for "how to switch activity on button press in Android".

Launch preferred application upon long clicking a button

So I have a button, when its pressed once it opens the calendar application, however some of my other other devices don't have the calendar I have described in the method so I have created an onLongCLick method, so when a user long clicks the button, they get to choose which app they want to launch. Once they choose the app, its set. So when they click button normally it launches the app they chose. How can I go about achieving this ??
Thanks for your time.
My longclick methodC
// Hold (onlongclick) to initiate choose app to launch
date_launch.setOnLongClickListener(new OnLongClickListener() {
public boolean onLongClick(View arg0) {
// choose app to launch and save it
return true;
}
});
Find the available activities via PackageManager.
public abstract List<ResolveInfo> queryIntentActivities (Intent intent, int flags)
Create a dialog for choosing apps.
Once the app is chosen, launch the package in onClick.

Setting splitActionBarWhenNarrow from Java on Android

I'm wondering if it would be possible to tell android to split the ActionBar only when I want it to, but on the same Activity. My use case is that by default, the actions I have on the bar are OK to be collapsed, but on a long click on an item, I enter an "Edit Task" mode, where the action bar is used to provide some shorthands to edit a task. I'd like this "edit mode" to use the split action bar, as it has icon's that are better off to be visible right away, and keep the "not split" action bar for the general view - where it's just "settings" etc.
So the question is, can I set android:uiOptions="splitActionBarWhenNarrow" from the code, instead of hardcode it in the Manifest?
PS: I'm using ActionBar Sherlock.
The native action bar can be set into split mode by calling getWindow().setUiOptions(ActivityInfo.UIOPTION_SPLIT_ACTION_BAR_WHEN_NARROW).
Window UI options cannot be read after they are set so with ActionBarSherlock you have to call getSherlock().setUiOptions(...). You don't have to call both. ABS will automatically call the above when appropriate.
This must be done before the decor view has been created. The safest place to put this call to ensure that always happens is in your activity onCreate method before you call super.onCreate.
Take a look at the ActionBarSherlockSamples, SplitActionModes.java. In this example, when the button 'Start' is pressed, a split action bar shows up in the bottom of the screen:
Call this to show the split actionbar:
mMode = startActionMode(new AnActionModeOfEpicProportions());
mMode is type of ActionMode and you need to call 'finish()' on it when you want the action bar to go away.
AnActionModeOfEpicPropotions is an implementation of ActionMode.Callback:
private final class AnActionModeOfEpicProportions implements ActionMode.Callback {
#Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
// add your menu here...
}
#Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
// handles your action menu clicked event
return true;
}
}
I was just trying if I could have an ActionBar in one Activity and a Split one in another.
I added the action bar in onCreateOptionsMenu in both the activities and added
getWindow().setUiOptions(ActivityInfo.UIOPTION_SPLIT_ACTION_BAR_WHEN_NARROW);
right before onCreate in the activity I wanted the split action and to my surprise it worked. :)
Then I used getActionBar().hide() to hide the split action bar on button click and it worked too.
I guess if you could try this, you can get this working and customized to your need. Hiding it initially and onLongClick showing it up and after the necessary actions are performed hiding it again.
(The only thing I missed is checking this with support libraries. Will do and update you)
Hope, this might help you in some way. Happy coding :)
private final class AnActionModeOfEpicProportions implements ActionMode.Callback
{
#Override
public boolean onCreateActionMode(ActionMode mode,Menu menu)
{
// add your menu here...
}
#Override
public boolean onActionItemClicked(ActionMode mode,MenuItem item)
{
// handles your action menu clicked event
returntrue;
}
}

Categories