How to fix the share icon in the support actionbar - android

I'm trying to implement the share functionality within my app. So far it works fine and I can share text to all other apps. The problem is the way it's shown.
I want something like just the share icon visible and then when user taps on it, it opens the OS dialog and lets user choose the app they want to share content to.
var share_article = menu.FindItem (Resource.Id.action_share);
var share_article_provider = (Android.Support.V7.Widget.ShareActionProvider) Android.Support.V4.View.MenuItemCompat.GetActionProvider (share_article);
share_article_provider.SetShareIntent (CreateIntent ());
and the xml:
<item
android:id="#+id/action_share"
myapp:showAsAction="ifRoom"
android:title="share"
myapp:actionProviderClass="android.support.v7.widget.ShareActionProvider" />
My app currently looks like this:
There's also a white border around it that I don't like.
Is there any way to change the icon??
How do I fix it??

You just want to turn off your share history.There is no official API to do this, but you can make your own ShareActionProvider. Actually there are two similar question on SO:
How do you turn off share history when using ShareActionProvider?
How to hide the share action (which use most) icon near the share action provider?
Wish these could help you.

As mentioned here when using support library this can be fixed really easily. This method won't turn off the share history but will hide the icons from actionbar.
I just needed to subclass the Android.Support.V7.Widget.ShareActionProvider like the following: (C# using Xamarin)
public class MyShareActionProvider : Android.Support.V7.Widget.ShareActionProvider
{
public SingleArticleShareActionProvider (Context context) : base (context)
{}
public override View OnCreateActionView ()
{
return null;
}
}
and then inside OnCreateOptionsMenu use the MyShareActionProvider like:
var share_article = menu.FindItem (Resource.Id.action_share);
var share = new SingleArticleShareActionProvider (globalContext);
Android.Support.V4.View.MenuItemCompat.SetActionProvider (share_article, share);
share_article.SetIcon (Resource.Drawable.abc_ic_menu_share_mtrl_alpha);
share.SetShareIntent (CreateIntent ());
You can use any icon you like with the method SetIcon.

Related

What is the name of translate language menu control from Google Chrome's Android browser and how to implement it?

I noticed the menu on the bottom side of Google Chrome's Android web browser application. It is used for setting language for translation of pages. Can you help me identify what is this control's name?
I'm currently working on Xamarin.Forms project and would like to implement similar menu on the bottom side of my screen for all Android devices. Is that possible in Xamarin.Forms and how would the implementation look like?
I'm currently working on Xamarin.Forms project and would like to implement similar menu on the bottom side of my screen for all Android devices. Is that possible in Xamarin.Forms and how would the implementation look like?
There is no direct control in xamarin.forms that can serve this purpose. So you will need your own Custom View for this:
In PCL, create a custom control class(MyTabLayout):
public class MyTabLayout:View
{
}
In PCL page, using this control in Xaml:
<StackLayout>
<!--EndAndExpand will bottom the tab control-->
<local:MyTabLayout VerticalOptions="EndAndExpand"></local:MyTabLayout>
</StackLayout>
In YourProject.Android project Create your custom renderer:
[assembly:ExportRenderer(typeof(CustomTabsLayout.MyTabLayout),
typeof(MyTabLayoutRenderer))]
namespace CustomTabsLayout.Droid
{
public class MyTabLayoutRenderer:ViewRenderer<MyTabLayout,TabLayout>
{
Context baseContext;
public MyTabLayoutRenderer(Context context) : base(context)
{
baseContext = context;
}
protected override void OnElementChanged(ElementChangedEventArgs<MyTabLayout> e)
{
base.OnElementChanged(e);
//Below are test tabs, you can customize your tabs' styles here.
TabLayout tab = new TabLayout(baseContext);
tab.AddTab(tab.NewTab().SetText("tab1"));
tab.AddTab(tab.NewTab().SetText("tab2"));
tab.AddTab(tab.NewTab().SetText("tab3"));
tab.AddTab(tab.NewTab().SetText("tab4"));
tab.AddTab(tab.NewTab().SetText("tab5"));
SetNativeControl(tab);
}
}
}
Here is the result:

Use Ionic Tabs for Actions

I really like the style of the Tabs in Ionic 3 when you have an icon and a text:
https://ionicframework.com/docs/components/#tabs-icon-text
However in the App I am using I have 4 Actions. For example open the Camera, open Google Maps and so on. And this I want to display on the bottom of the page exactly in this kind of style.
How can I achieve this, since this is not the real purpose of the Tabs and since I haven't found a similar Component.
Just like you can see in the Tab docs:
Sometimes you may want to call a method instead of navigating to a new
page. You can use the (ionSelect) event to call a method on your class
when the tab is selected.
<ion-tabs>
<ion-tab (ionSelect)="chat()" tabTitle="Show Modal"></ion-tab>
</ion-tabs>
And then
export class Tabs {
constructor(public modalCtrl: ModalController) {}
chat() {
let modal = this.modalCtrl.create(ChatPage);
modal.present();
}
}

How to add an icon in navigation bar for navigation page in xamarin forms for android?

I have made simple navigation pages.
Now I want to add icon for android in navigation bar.
I added an screenshot and highlighted with black circle where i want to add an icon.
I also tried custom renderer.
That is provided answer from this post: Change icon on Navigation bar - Xamarin.Forms Android
But not worked for me.
Here it is
[assembly: ExportRenderer(typeof(NavigationPage), typeof(CustomMapRenderer))]
namespace XamarinFormsMaps.Droid
{
public class CustomMapRenderer : NavigationPageRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<NavigationPage> e)
{
base.OnElementChanged(e);
var bar = (Android.Support.V7.Widget.Toolbar)typeof(NavigationPageRenderer)
.GetField("_toolbar", BindingFlags.NonPublic | BindingFlags.Instance)
.GetValue(this);
bar.SetLogo(Resource.Drawable.icon);
}
}
}
Try this one!
I personally haven't used it but I guess you are looking for this:
NavigationPage.SetTitleIcon (this, "image.png");
This will set the title Icon in Xamarin Forms.
If you want to change the back button Icon, hamalaiv gave you this link
Thank you Dilmah.
It work for me.
With Xamarin.Forms 2.5, I change the constructor by
public CustomMapRender(Context context) : base(context)
to avoid warning of obsolete constructor.

How to disable selection highlight in listview xamarin.forms on android

I have created listview using xamarin.forms, I am searching for a way not to highlight the viewcell while tapping on the listview.
please check on the image below.
Thanks in advance :)
on your ListView SelectedItem event handler, you can do:
listview.SelectedItem = null;
that'll give you the on click highlight, but the state will be transient only.
In your case, I guess you'd like this because you're using 2 Images instead of Buttons for the arrows on the right, with a TapGestureRecognizer. Do you know the Button has an Image property? When clicking on a Button in a Cell, the Cell selected state shouldn't change.
Just put this in your custom theme:
<item name="android:colorActivatedHighlight">#android:color/transparent</item>
I want to share another solution I really like, because it's simple, you have to implement it once and it's really easy to use in XAML.
First we have to implement our own behavior. That's quite simple:
public class DeselectItemBehavior : Behavior<ListView>
{
protected override void OnAttachedTo(ListView bindable)
{
base.OnAttachedTo(bindable);
bindable.ItemSelected += ListView_ItemSelected;
}
protected override void OnDetachingFrom(ListView bindable)
{
base.OnDetachingFrom(bindable);
bindable.ItemSelected -= ListView_ItemSelected;
}
private void ListView_ItemSelected(object sender, SelectedItemChangedEventArgs e)
{
((ListView)sender).SelectedItem = null;
}
}
So we're just registering to the event when the behavior is set and unregister it when it's unset.
The event itself uses Stephane Delcroix approach.
Now everything you have to do in the ListView is to add the behavior like this:
<ListView ...>
<ListView.Behaviors>
<behaviors:DeselectItemBehavior />
</ListView.Behaviors>
I'm using: ListView SelectionMode = "None" in Xamarin.Forms.
For disabling Listview cell selection highlight in both Android and iOS, this link was very helpful
https://gist.github.com/jessejiang0214/63b29b3166330c6fc083
ProjectName.Android/Resources/values/styles.xml
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<style name="CustomTheme" parent="android:Theme.Holo.Light">
<item name="android:colorActivatedHighlight">#android:color/transparent</item>
</style>
</resources>
CustomAllViewCellRendereriOS.cs
using System;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly: ExportRenderer (typeof(ViewCell), typeof(MyAPP.iOS.CustomAllViewCellRendereriOS))]
namespace MyAPP.iOS
{
public class CustomAllViewCellRendereriOS : ViewCellRenderer
{
public override UIKit.UITableViewCell GetCell (Cell item, UIKit.UITableViewCell reusableCell, UIKit.UITableView tv)
{
var cell = base.GetCell (item, reusableCell, tv);
if (cell != null)
cell.SelectionStyle = UIKit.UITableViewCellSelectionStyle.None;
return cell;
}
}
}
This seems to be the right & best way...!
You can't, you have to implement a custom render. If you just set selected item to null, it will remove the selected color. But you will first have selected the item and then deselected it again (multible events) but your did'nt see it :-). If you enabled tilt effect on Windows Phone, the tilt is still happen because of all the event!
But i would like to see the Xamarin Forms team implement a CanSelect properties on the listview.
I want to suggest you another solution.
You can add:
IsEnabled="False"
in your listview widget.
In my case this solution works well.

button bar similar to twitter app for android

I want to obtain a similar tab effect with the button bar of twitter app.
I wish to click on a button and change the view down. I can switch activity but I think It's wrong, or not?
The top bar have to be fix like a frame. Like this:
Ok now I post a part of my idea (i found something similar here: http://www.talkandroid.com/android-forums/android-development-answers-tutorials-code-snippets/1515-how-i-open-image-imagebutton.html)
code:
newsButton = (ImageButton) findViewById(R.id.news);
newsButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
// on click go to the news view (no activity yet)
setContentView(R.layout.news);
}
});
Like in the Google IO App?
If so, the Source Code is freely available here.
Okay, a little tour on how Google does it:
The activity_home.xml-layout
includes (Line 21) the
actionbar.xml-layout (This is done
in every Layout so the Actionbar
must not always be duplicated).
The actionbar.xml-Layout
creates a LinearLayout for
the UI-Elements.
Then, for example the
HomeActivity-Activity sets
the content view to the
activity_home.xml-layout, receives
an ActivityHelper-class and calls
its setupActionBar()-method.
The mantioned ActivityHelper-class
is in the hg/ android/ src/ com/
google/ android/ apps/ iosched/
util/-package and has the
setupActionBar()-method which
creates the Action bar.
This might be easier then it looks. Read your way through the Source Code and try it yourself.
I think these controls are Radio Button/ Radio Group with customization.

Categories

Resources