Showcaseview not displaying action bar items - android

So in my project I am using a showcaseview to create a tutorial for the user. When I point the ShowcaseView to any action bar id, the result is this:
My question is is it possible to have the showcaseview target the specific items in the action bar rather than just a general overview like the one shown above. The code is being run in the overridden onCreateOptionsMenu method and is in the context of an activity. Here is the code that I am currently using:
actionBarViews = new ShowcaseViews(activity);
ShowcaseView.ConfigOptions co = new ShowcaseView.ConfigOptions();
co.hideOnClickOutside = true;
actionBarViews.addView(new ItemViewProperties(R.id.sendmessage,
R.string.send_title, R.string.send_tutorial,
ShowcaseView.ITEM_ACTION_ITEM, 0, co));
actionBarViews.addView(new ItemViewProperties(R.id.tutorial_menu,
R.string.tutorial_title, R.string.tutorial_tutorial,
ShowcaseView.ITEM_ACTION_OVERFLOW, 0, co));
actionBarViews.show();
If it is impossible to currently target actionbaritems, is there another way to go about implementing a tutorial.

This may be a little late, but this may be useful for other users who find this thread. I used the following code to highlight my action button with ShowCaseView
//for action button with id "ACTION_BUTTON_ID"
ShowcaseView.ConfigOptions co = new ShowcaseView.ConfigOptions();
co.showcaseId = ShowcaseView.ITEM_ACTION_ITEM;
co.hideOnClickOutside = true;
ActionItemTarget target = new ActionItemTarget(this.getActivity(),R.id.ACTION_BUTTON_ID);
final ShowcaseView sv = ShowcaseView.insertShowcaseView(target,getActivity(),R.string.instruction_title_text,R.string.instruction_details_text);
sv.show();

use it like this
new ShowcaseView.Builder(activity)
// .withMaterialShowcase()
// .setStyle(R.style.CustomShowcaseTheme3)
.setTarget(Target.NONE)
.setOnClickListener(this)
//.withMaterialShowcase()
.blockAllTouches()
.useDecorViewAsParent() //this is the difference
.build();
then target your view in action bar

have you tried to use ActionBarSherlock? It supports old compatibility and has quite a lot of available examples.

Related

How to create progress bar in android without using progress bar widget in xml file?

I want to do something new in my app. I want to create Progress Bar without using tag of xml in android .is there any way to do that ? if yes then please share with me? The purpose of doing this is that i don't want to declare Progress Bar for each of my layout file. I completely want to make it using Kotlin Code in android. thanks in advnance
You can use the ProgressIndicator provided by the Material Components Library.
For example a CircularProgressIndicator:
val layout = findViewById<LinearLayout>(R.id.layout)
val indicator = CircularProgressIndicator(this)
indicator.isIndeterminate = true
indicator.trackColor = ContextCompat.getColor(this,R.color.xxx)
indicator.indicatorSize = resources.getDimensionPixelSize(R.dimen.indicator100dp)
indicator.setIndicatorColor(ContextCompat.getColor(this,R.color.xxx))
indicator.show()
layout.addView(indicator)
Or a LinearProgressIndicator
val indicator = LinearProgressIndicator(this)
indicator.isIndeterminate = true
indicator.trackColor = ContextCompat.getColor(this,R.color.xxxx)
indicator.trackThickness = resources.getDimensionPixelSize(R.dimen.cornerSize8)
indicator.setIndicatorColor(ContextCompat.getColor(this,R.color.xxx))
indicator.show()
layout.addView(indicator)

Size of ShareAction icon issue on ActionBar with ShareActionProvider-v7

I was working around my old ShareAction on my ActionBar and it was working since I updated my Packages on SDK Manager. I saw this doc from Google which says,
To add a "share" action to your activity, put a ShareActionProvider in
the app bar's menu resource. For example:
And I've added the same without adding any Icons:
<item android:id="#+id/action_share"
android:title="#string/share"
app:showAsAction="ifRoom"
app:actionProviderClass="android.support.v7.widget.ShareActionProvider"/>
I was using:
app:actionProviderClass="Mypackagename.ShareActionProvider"
With a custom ShareActionProvider with the following code.you can see it here.
I saw a hack or a trick to do that (with ShareActionProvider-v4) and everything was good since I decided to use android.support.v7.widget.ShareActionProvider.
So, Here is my currently code:
<item
android:id="#+id/shareac"
android:title="#string/share"
app:actionProviderClass="android.support.v7.widget.ShareActionProvider"
app:showAsAction="always" />
I didn't use the Icon because here the doc says,
You do not need to specify an icon, since the ShareActionProvider
widget takes care of its own appearance and behavior. However, you do
need to specify a title with android:title, in case the action ends up
in the overflow menu.
And here is what I've done so far:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main_details, menu);
// Locate MenuItem with ShareActionProvider
MenuItem item = menu.findItem(R.id.shareac);
// Fetch and store ShareActionProvider
mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(item);
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
Bundle extra = getIntent().getExtras();
String title = extra.getString("title");
Bundle extraurl = getIntent().getExtras();
String url = extraurl.getString("url");
shareIntent.putExtra(Intent.EXTRA_TEXT, "Check this new project from something : " + title + url);
shareIntent.setType("text/plain");
mShareActionProvider.setShareIntent(shareIntent);
return true;
}
So, here what I see right now in Android Studio 1.5.1 Is,
And if run and compile the app:
As you can see, the size of ShareAction is too much. (It's violating the MaterialDesign guideline I guess).
I forgot to say, I've already tried android:icon="#mipmap/ic_share" which that was working with my previous method/trick. But, check this Preview from AndroidStudio:
And here is after compiled:
Nothing changed!
So, my question: is that a bug or what am I doing wrong here?
Intent.createChooser didn't work also: from: https://stackoverflow.com/a/34797718/4409113
Edit:
The most interesting part, i just saw the same design and the same resutls from Google on the following course and on that app which they've called it SunShine app:
Applink
Course:
https://www.udacity.com//course/viewer#!/c-ud855/l-3961788738/m-4294896397
Okay, As ianhanniballake at this post said,
Icons in material design are 24dp x 24dp, as properly reflected by the
SearchView. However, ShareActionProvider has not yet been updated to
material design by default.
By the way, i've just posted a question/report to code.google.com which you can see it here:
http://code.google.com/p/android/issues/detail?id=200335
It seems that default icon is 24dp x 24dp but it should be like this:
But now, it is like this:
Seems to be a bug and still waiting for accepting or answering about it.I'll update this post if they answered.7 days passed!
UPDATE:
Finally, they've assigned the defect on to the development team and they will update this issue with more information as it becomes available.
Big thanks to ssingamc...#google.com at Google for support.
The answer is available here: http://code.google.com/p/android/issues/detail?id=200335#c10
I will update this answer if any updates or any fixes was available.
UPDATE: http://code.google.com/p/android/issues/detail?id=200335#c12
Hi, The development team has fixed the issue that you have reported
and it will be available in a future build. Thanks
Icons in material design are 24dp x 24dp, as properly reflected by the SearchView. However, ShareActionProvider has not yet been updated to material design by default.
You can set actionModeShareDrawable in your theme to set the share icon in the ShareActionProvider:
<item name="actionModeShareDrawable">#drawable/share_icon</item>
Note that ShareActionProvider is not found anywhere in the material design guidelines and with Android M's Direct Share capability (which requires you use a standard share intent at this time), it is unclear on whether the ShareActionProvider is a suggested pattern any more.
For more detail Visit Here.
AppCompat ShareActionProvider icon is too big compared to other icons
Change the icon Pragmatically
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main_details, menu);
// Locate MenuItem with ShareActionProvider
MenuItem item = menu.findItem(R.id.shareac);
// Fetch and store ShareActionProvider
mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(item);
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
Bundle extra = getIntent().getExtras();
String title = extra.getString("title");
Bundle extraurl = getIntent().getExtras();
String url = extraurl.getString("url");
shareIntent.putExtra(Intent.EXTRA_TEXT, "Check this new project from something : " + title + url);
shareIntent.setType("text/plain");
mShareActionProvider.setShareIntent(shareIntent);
//Here
item.setIcon(getResources().getDrawable(R.drawable.ic_share));
return true;
}
or Theme
<item name="actionModeShareDrawable">#drawable/ic_share</item>
If you don't need custom icon for share menu item then try android resource for share menuitem as below:
<item android:id="#+id/action_share"
android:title="#string/share"
app:showAsAction="ifRoom"
android:icon="#android:drawable/ic_share"
app:actionProviderClass="android.support.v7.widget.ShareActionProvider"/>
See here

ShowcaseView highlights wrong item

I use ShowcaseView like this:
ActionItemTarget target = new ActionItemTarget(this, R.id.menu_search);
ShowcaseView sv = new ShowcaseView.Builder(this, true)
.setTarget(target)
.setContentText("Press this to search")
.setStyle(R.style.CustomShowcaseTheme)
.build();
But when I start app the first, ShowcaseView highlights home button. When I try to start app again, correct ActionBar item is showcased.
My app doesn't use compatibility libraries like ActionbarSherlock.
Any idea why this may be happening?
As requested:
The problem is that you are trying to retrieve an id for a view that is not in the hierarchy yet. According to the activity view cycle the menu is only created after onCreate. The best solution is to use onCreateOptionsMenu but even here R.id.menu_search will not return a valid id because the menu hasn't been created yet. Since the order of events has changed in API lvl 16 I suggest you hack it a little bit. You can create a handler on your onCreate() and execute a postDelayed runable. The code will be executed after the menu has been designed. On that runable you can retrieve the view for R.id.menu_search and highlight it.
I will try to present sample code here:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
new ShowcaseView.Builder(this)
.withMaterialShowcase()
.setTarget(new ToolbarActionItemTarget(this.toolbar, R.id.menu_search))
.setContentText("Here's how to highlight items on a toolbar")
.build()
.show();
return true;
}
Note: toolbar declare as member of the class.

The title/action bar ID in android?

I wanted to try out this funny title bar coloring, but it doesn't work for me as
getWindow().findViewById(android.R.id.title);
returns null. So I had a look at it with Hierarchy Viewer and found out that the view is called id/action_bar instead. But there's no R.id.action_bar (autocomplete doesn't offer it and there's nothing like this is R.java).
So now I'm doubly confused:
Is android.R.id.title sort of obsolete now (I'm using version 16 in my emulator)?
Where does id/action_bar come from?
What's the recommended and simple practice w.r.t. compatibility?
Should I get ActionBarSherlock? I originally just wanted to change the title bar color... not fool around with it a lot.
Use the code below to get the ActionBar's id:
val actionBarId = resources.getIdentifier("action_bar", "id", packageName)
And use findViewById you can find the action bar.
Then find the title from actionbar's children (in normal cases):
val actionbar = findViewById<ViewGroup>(actionBarId)
for (view in actionbar.children) {
if (view is TextView) {
// this is the titleView
}
}
However, if you just want to change the title view's text, just use getSupportActionBar:
supportActionBar?.apply {
// set title text
title = "Hello"
// set colored title text
val coloredTitle = SpannableString("Hello")
coloredTitle.setSpan(ForegroundColorSpan(Color.RED), 0, coloredTitle.length, 0)
title = coloredTitle
}
I would recommend using ActionBarSherlock if you're looking for compatibility with Android versions before API level 14 / Android 4.0.
Changing the background of the ActionBar is straightforward and is most easily done via styles. See the "Background" section of http://android-developers.blogspot.com/2011/04/customizing-action-bar.html
You can also change it via code. Put this in your onCreate():
GradientDrawable gradientDrawable = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, new int[] {Color.RED, Color.GREEN});
getActionBar().setBackgroundDrawable(gradientDrawable);
Here is a screenshot of this code in action:

Action bar for Android 2.1

Is there action bar for Android Level 7 or something else that I can use as action bar?
I need to build an app which is using action bar for Android 2.1
JohanNilsson has actually created a ActionBar library which is available on GitHub.
Direct link.
here you go. The officle android article is called: ActionBarCompat - Action Bar Compatibility. (just in case the link wont work for ever)
Well, you should try this open source project http://actionbarsherlock.com , you will find it's full definition on this website
In the newest version it will have support for features provided by ICS.
TypedArray a = mActivity.getTheme().obtainStyledAttributes(R.style.AppTheme, new int[] {
R.attr.actionbarCompatItemHomeStyle,
R.attr.actionbarCompatItemStyle
});
int actionbarCompatItemHomeStyle = a.getResourceId(0, 0);
int actionbarCompatItemStyle = a.getResourceId(1, 0);
ImageButton actionButton = new ImageButton(mActivity, null,
itemId == android.R.id.home ? actionbarCompatItemHomeStyle : actionbarCompatItemStyle
);
The equivalent of action bar in pre-Honeycomb versions of Android is the options menu, accessible under Menu button.
In July 2013 Google added action bar compatibility back to 2.1 (7+) in New "v7 appcompat library"
http://developer.android.com/tools/support-library/index.html

Categories

Resources