How to custom ActionBar android with Xamarin Forms? - android

I work with Xamarin Forms. My Android activity extends FormAppCompatActivity. I use a MasterDetailPage and this.Detail is init with new NavigationPage(new PagePerso()). I have a xamarin.forms.view and its renderer to Android.
I would like put this inside the NavigationBar (ActionBar to Android).
I tried to use a NavigationPageRender. Then I tried to use :
protected override void OnElementChanged(ElementChangedEventArgs<NavigationPage> e){
base.OnElementChanged(e);
Android.Views.View actionBar = base.ViewGroup.GetChildAt(0);
...}
Thanks you in advance for your help !
If you have an other solution, suggest me ! (I use Xamarin forms, FormAppCompat, MasterDetailPage and NavigationPage to its Detail)
Solution and new problem :
I have finally come to add an Android.View inside ActionBar using ViewGroup. Now, my problem is that I want to add a custom view (xamarin) ...
Android.Widget.Button bt = new Android.Widget.Button(base.ViewGroup.Context);
ViewGroup actionBar = (ViewGroup) base.ViewGroup.GetChildAt(0);
actionBar.AddView(viewGroup);
The button with this code is added well.
So I have MyCustomView view = new MyCustomView();
And I would like add view as viewGroup previously but it's not an Android.Views.View.
Thanks you in advance !

Have you tried actionBar.SetDisplayShowCustomEnabled(true);?
I have recently seen some inconsitencies with this approach using AppCompat that I'm about the report to Xamarin.

Related

How can I add android widget to ViroCore scene?

I am developing panorama application and I cannot find some ways to implement my Android layouts or Android widgets(TextView, ImageView etc.) to my scene on ViroView.
Is it possible to do in this 3rd party library(ViroCore)?
Thanks, a lot!
first you need to inflate the view , then create an AndoridViewTexture ,and finally use the function attachview and give it the inflated view as a parm.
AndroidViewTexture androidTexture = new AndroidViewTexture(viroView.provideView(), pxWidth, pxHeight, isAccelerated);
androidTexture.attachView(inflated);

Insert icon in a tabbed page(Android) on xamarin form

I'm new to StackOverflow community!
I need help with one problem with android in Xamarin Forms. To be precise... I tried with some friends to build our first app. We choose(with the help of our University professor) Xamarin for the cross-platform development of Android and iOS for both systems using the Xamarin Forms. I created the interface part of the app and now I am stuck in a fort with big walls. When I try to add a Tabbed Page the icon for the functional bar, the app crashes(Android) but in iOS, the problem doesn't appear...
I'd try with some solution... like :
-Render in the NameApp.Droid adds different renderer only for the android part but no result...
-Try another way to insert the icon in the .xaml file directly but no result...
-Try to follow another way to modify the .axam file for the "Theme" part
but no result...
I want to integrate all the stuff on time only in the "Main Project". I don't want for now touch the "nameProject.Droid" or "nameProject.iOS" part, But try to make in one shoot both(Andriod & iOS). I've found a different bug in Android (è.é) but for this, I am going crazy...
But I need to modify the ".Droid" no problem I accept the challenge!
This is the result I aspire to create.
"https://storage.googleapis.com/material-design/publish/material_v_12/assets/0B6Okdz75tqQsbHJuWi04N0ZIc0E/components-tabs-usage-mobile7.png"
This is the way I add the Icon in the Tabbed Page. An assumption I add all the stuff in the "Resource" in ".Droid" and ".iOS :
var MainPageTabbed = new MPageTabbed();
var Profile = new Profile();
var ListChat = new ListChat();
if (Device.RuntimePlatform == Device.Android)
{
MainPageTabbed.Icon = "ldpi.png";
Profile.Icon = "ldpi2.png";
Chat.Icon = "ldpi1.png";
}
if (Device.RuntimePlatform == Device.iOS)
{
MainPageTabbed.Icon = "ldpi.png";
Profile.Icon = "ldpi2.png";
ListChat.Icon = "ldpi1.png";
}
NavigationPage.SetHasNavigationBar(this, false);
Children.Add(MainPageTabbed);
Children.Add(Profile);
Children.Add(ListChat);
Someone can help me please to find a solution?
Here you have an example of how to use the TabbedPage in xamarin forms:
https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/navigation/tabbed-page/
... Xamarin.forms renders Android tabbed-pages as something called a viewpager combined with a TabPagerStrib, and it looks like the example in the link above.
You might read about BottomNavigationBar for Android instead, or look at this link for a TabPagerStrip with an image:
https://forums.xamarin.com/discussion/39937/adding-icons-to-a-pagertabstrip-instead-of-text
If anyone is interested in a FontAwesome custom icon implementation I followed this tutorial to begin with: FontAwesome with Xamarin Forms
Unfortunately he doesn't give an example of integrating with tabbed pages but after some experimenting I finally figured out a simplified Xaml way to render it without a custom tabbed renderer:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:IBMobile.Views"
xmlns:local2="clr-namespace:FontAwesome"
x:Class="IBMobile.Views.HomePage"
Visual="Material">
<ContentPage.IconImageSource>
<FontImageSource FontFamily="{StaticResource FontAwesomeSolid}" Glyph="{x:Static local2:IconFont.Home}" />
</ContentPage.IconImageSource>

How to load a URL in chromium?

I created a new activity which extends SingleTabActivity and it calls:
getActivityTab().loadUrl(new LoadUrlParams("http://google.com.vn", PageTransition.AUTO_TOPLEVEL));
But nothing is showing up. Do I need anything else to tell Chromium to render web content?
Thank you!
I found the answer. Override finishNativeInitialization and add following lines:
LayoutManager layoutDriver = new CustomTabLayoutManager(getCompositorViewHolder());
initializeCompositorContent(layoutDriver, findViewById(org.chromium.chrome.R.id.url_bar),
(ViewGroup) findViewById(android.R.id.content),
(ToolbarControlContainer) findViewById(org.chromium.chrome.R.id.control_container));

Grabbing a pointer to a TextView of a tab on the action bar?

Some other users and I are developing an Android application for the Stack Exchange chat network. We're adding a tutorial for each activity to explain the UI to the user. However, we've run into a bit of a road block.
The tutorial library wants a pointer to a view (be it a TextView, ImageView, whatever) in order to get the coordinates of the view in the display so it knows where to draw the drop shadows and stuff.
We have one activity which uses the standard "Tabbed Activity" from Android Studio, so we aren't using any custom toolbars.
The action bar looks like this:
And we want to grab a pointer to the TextView on each tab that holds the title of the tab.
So for example, we want to be able to access this Textview:
We haven't been real successful in finding anything on the internet about how to do this. It appears to be relatively easy if you're using a custom toolbar, but we aren't.
Digging in the AOSP source code, we found a potential way to do it, but the fields that we needed access to were either private or otherwise unaccessible from the main activity code.
So the question is, how can we grab a pointer to that TextView? Is it even possible?
Well, it isn't pretty but we found a way to do it. Using the layout inspector in Android Device Monitor to look at the view hierarchy, we were able to grab a pointer to it in the following way.
Keep in mind:
You may need to adjust for your activity's layout
If you're using a custom toolbar there's an easier way to do this
That being said, here's what worked for this specific use case:
ViewGroup viewGroup = (ViewGroup) getWindow().getDecorView();
LinearLayout testb = (LinearLayout) viewGroup.getChildAt(0);
FrameLayout testc = (FrameLayout) testb.getChildAt(1);
ActionBarOverlayLayout testd = (ActionBarOverlayLayout) testc.getChildAt(0);
ActionBarContainer teste = (ActionBarContainer) testd.getChildAt(1);
LinearLayoutCompat testg;
if (getResources().getConfiguration().orientation == ORIENTATION_PORTRAIT)
{
ScrollingTabContainerView testf = (ScrollingTabContainerView) teste.getChildAt(2);
testg = (LinearLayoutCompat) testf.getChildAt(0);
}
else //Landscape
{
Toolbar teste2 = (Toolbar) teste.getChildAt(0);
ScrollingTabContainerView testf = (ScrollingTabContainerView) teste2.getChildAt(0);
testg = (LinearLayoutCompat) testf.getChildAt(0);
}
testg.setId(android.R.id.tabcontent);
//String IdAsString = testg.getResources().getResourceName(testg.getId());
//Log.e("TestG", IdAsString);
TutorialStuff.chatsExplorationTutorial(this, testg);
And here's the end result:

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.

Categories

Resources