In my app i am working with actionbar library,(Bcz i am using api 2.2)
https://github.com/johannilsson/android-actionbar
I have 6 classes in my app. Each class contains different action items in actionbar. I want for different different action it will work differently.
But in actionbar library there is single click listener for all action.
But I want to call clik listener from my activity.
How can i do that?
For each activity you can use code like below. You may wish to use a superclass to avoid duplication of code. For each button on the action bar you need to create an intent, and then specify that intent as the action for the button.
// Set the Action Bar title
actionBar = (ActionBar)findViewById(R.id.actionbar);
actionBar.setTitle(R.string.app_name);
// Set up the Action Bar home/icon button
actionBar.setHomeLogo(R.drawable.icon);
Intent homeIntent = new Intent(Intent.ACTION_VIEW);
homeIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
homeIntent.setClassName(context, TaxiMap.class.getName());
actionBar.setHomeAction(new ActionBar.IntentAction(this, homeIntent, R.drawable.icon));
// Add an Action Bar button
Intent actionIntent = new Intent(Intent.ACTION_VIEW);
actionIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
actionIntent.setClassName(context, TaxiMap.class.getName());
actionBar.addAction(new ActionBar.IntentAction(this, actionIntent, R.drawable.ic_action_icon));
Related
When I start Wifi setting page from android's setting page, there is a back button in the top action bar. But there is not when I start Wifi setting from my own app.
The code I am using is:
Intent intent = new Intent(Settings.ACTION_WIFI_SETTINGS);
startActivity(intent);
I know that the wifi setting activity and my activity are already in the same back stack. Is there any way to show the back button in the action bar?
As far as I'm aware, there's no way to do what you want. However, I think that even if there were, it is unlikely that you would actually want to do it.
The "back" button in the action bar is actually an Up button. Clicking it wouldn't take the user back to your app; it would take the user up one level within the device settings.
https://developer.android.com/design/patterns/navigation.html
Try adding
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
or try
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
ComponentName cn = new ComponentName("com.android.settings", "com.android.settings.wifi.WifiSettings");
intent.setComponent(cn);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity( intent);
I am trying to create a floating action button in android and want to add actions to those small sub buttons to start new activity by clicking them. I successfully managed to create those sub buttons but cannot assign action to them to start new activity.
I'm not sure i have understand what you want to do.. but seems you want simple open a new activity onClick.. so you can do in this way:
Button floatingBtn = (Button)findViewById(R.id.fab);
floatingBtn.setOnClickListener = new(view.onClickListener()
{
Intent i = new Intent(this, Activity.class);
startActivity(i);
});
Remember to insert the new activity in the manifest
I have different Intent filters set on an Activity to handle different file pattern. Everything works fine, but what I would like is to be able to display different Activity name in the Android action chooser screen depending on the file pattern. For now, it just displays the activity label...
Is it possible to override the label per Intent filter ?
The <intent-filter> element supports an android:label attribute.
Maybe this is the solution:
ActionBar ab = getActionBar();
switch(filePattern) {
case 0:
ab.setTitle("My Title");
break;
...
default:
ab.setTitle("Nothing");
}
I have created a simple bar code generator using XZing library.
to do it I used a code :
Intent intent = new Intent("com.google.zxing.client.android.ENCODE");
intent.putExtra("ENCODE_FORMAT", "UPC_A");
intent.putExtra("ENCODE_DATA", "12345678901");
startActivity(intent);
I need to get rid of the title in this activity(grey bar in top of activity) ! Could you tell me how to do it ?
Image
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
before the setContentView() in onCreate()in the Activity where you want to remove the titlebar.
You cannot change the title bar of someone else activity. If you have the source then you can used the above suggestion.
I have a normal notification system that looks like this:
Notification notification new Notification(
R.drawable.alerts_notification,
alertTitle,
System.currentTimeMillis());
Intent intent = new Intent(mContext, MyActivity.class);
intent.setAction(MyActivity.ONE_ACTION);
PendingIntent pi = PendingIntent.getActivity(mContext, 0, intent, 0);
mNotifMan.notify(ID, notification);
Notice that I'm using ONE_ACTION as the action of the intent. What I do is verify the action on the activity and select one of the tabs (it's a TabActivity).
All that works fine if the activity is closed, because the Intent will open the activity and then I will decide what to do depending on the action in the Intent. But, if the activity is already opened, it launches a new activity. On the other hand, if I add the flag Intent.FLAG_ACTIVITY_SINGLE_TOP, the activity is not launched twice but I can't the tab is not chosen either.
So, how can choose a tab by clicking on the notification?
Have your intent open your tab activity and put an extra in it denoting the tab. When you detect action resume get a handle on your tab controller and change the tab through code.
OK, I found how to do it... it seems I hadn misread the documentation. What I did was:
Add this to the activity in the AndroidManifest.xml file: android:launchMode="singleInstance"
Overwrite the onNewIntent(Intent intent) method on the activity and put there all the logic to select the tabs etc.
Launch the intent with the flag Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT
#schwiz, thanks for your answer though.