Custom Tabbed Page Renderer Xamarin Android - android

So know how to set up a custom renderer (only partially apparently) with an OnElementChanged method. I followed this (http://forums.xamarin.com/discussion/17654/tabbedpage-icons-not-visible-android)
protected override void OnElementChanged(ElementChangedEventArgs<TabbedPage> e)
{
base.OnElementChanged(e);
_activity = this.Context as Activity;
}
This gets hit, but it never displays the page afterwards.
Anyone have any ideas?

It is showing up now. I had to use the base class of TabbedRender rather than TabbedPageRenderer. I also had to add this.SetWillNotDraw(false) in the CustomRenderer constructor.

Here you can find a full TabbedPageRenderer ready to be modified. It comes directly from Xamarin.Forms Android.
Still I'm trying to set a different Font Size...

Related

React native draggable flatlist not draggable

I tried implementing react-native-draggable-flatlist to my project, but I'm not able to drag the elements. I am able to "pick them" (They get bigger if I press them), but I can't move them to another position.
I had this problem before and found a working soloution in a GitHub issue, but as it seems, MainActivity.java has changed in some version and I don't know how to correctly upgrade it.
The soloution I found:
When I add the #Override for the ReactActivityDelegate, my App crashes after the build.
I noticed that my MainActivity.java looks a little bit different, it seems like the ActivityDelegate is Managed through a class called MainActivityDelegate which extends ReactActivityDelegate:
public static class MainActivityDelegate extends ReactActivityDelegate {
public MainActivityDelegate(ReactActivity activity, String mainComponentName) {
super(activity, mainComponentName);
}
#Override
protected ReactRootView createRootView() {
ReactRootView reactRootView = new ReactRootView(getContext());
// If you opted-in for the New Architecture, we enable the Fabric Renderer.
reactRootView.setIsFabric(BuildConfig.IS_NEW_ARCHITECTURE_ENABLED);
return reactRootView;
}
}
It seems like I have to change something here to achieve the same result, but I don't really know what.
EDIT:
According to the RNGH docs you shouldn't change your MainActivity.java that way anymore and wrap your whole App into a GestureHandlerRootView. Some Libaries like react-native-navigation do this by default (in my case). BEcause of that (I think) my App gets completely grey when I use a GestureHandlerRootView. If I don't addd it myself, so I use the one from neavigaion, I still can't drag the items in my list.
I fixed it by wrapping my screen component in a GestureHandlerRootView

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:

Xamarin Forms Custom Renderer for Android not displaying

I am trying to render a checkbox in a Xamarin Forms app. There is nothing rendered at runtime, as far as I can tell the renderer is not even getting called.
Does anyone understand what I am missing or doing incorrectly?
Here is my class in Forms:
public class LegalCheckbox : View
{
public LegalCheckbox ()
{
}
}
And my custom renderer class in Droid:
public class CheckBoxRenderer : ViewRenderer<LegalCheckbox, CheckBox>
{
protected override void OnElementChanged (ElementChangedEventArgs<LegalCheckbox> e)
{
base.OnElementChanged (e);
CheckBox control = new Android.Widget.CheckBox(this.Context);
control.Checked = false;
control.Text = "I agree to terms";
control.SetTextColor (Android.Graphics.Color.Rgb (60, 60, 60));
this.SetNativeControl(control);
}
}
Along with the Assembly Directive:
[assembly: ExportRenderer(typeof(demo.LegalCheckbox), typeof(demo.Droid.CheckBoxRenderer))]
Took your code and fired up a new project with it. The code appears to function fine.
Only thin I can think that might be causing you an issue is the location of you assembly attribute. I typically place them just above the namespace declaration in the same file as my renderer.
I threw what I created up on my github maybe you can spot the difference.
https://github.com/DavidStrickland0/Xamarin-Forms-Samples/tree/master/RendererDemo
#Thibault D.
Xlabs isn't a bad project but its basically just all the code the opensource community came up with during the first year or so of Xamarin.Forms life. Its not really "Their Labs projects" and considering how much of it is marked up with Alpha Beta and the number of bugs in their issues page it's probably best not to imply that the Xamarin company has anything to do with it.
I am not sure if that is the issue but it would make more sense to me if your LegalCheckbox would inherit from a InputView rather than View.
Also, even if Xamarin.Forms does not have a Checkbox control you can still have a look at their "Labs" project here:
https://github.com/XLabs/Xamarin-Forms-Labs/wiki/Checkbox-Control
(And I can actually see that they inherit from View...)

How to make a web app for android?

I’ve been making android apps for like 4-5 days now. So i’m wondering if you know how I can make a web app? I have been looking through many tutorials, but none shows directly how I can make an app that displays the content from a website, and that I can decide what I want and don’t want to display. So I really just want to customize a website into an app and make my own layout. I know how the WebView and WebContent works and all that stuff, but I don’t know how I can do what I described here.
So what do I need to learn and know to make an app like that?
You can do it by fill your xml layout with EdidText for the url and Buttons for Go, back, forward and so on, finally you need webview in this xml layout.
for the java code you can check the below sample.
public class SimpleBrowser extends Activity implements OnClickListener {
WebView myBrowser;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.simplebrowser);
//here the code for initialize and set yourwebView Settings.
myBrowser= (WebView) findViewById(R.id.wvBrowser);
//the below line to enable javascript if you want that
myBrowser.getSettings().setJavaScriptEnabled(true);
//here another settings could be enabled for you your webview
myBrowser.getSettings().setLoadWithOverviewMode(true);
myBrowser.getSettings().setUseWideViewPort(true);
try {
//here the default web page
ourBrow.loadUrl("http://www.google.com");
}catch (Exception e){
e.printStackTrace();
}
}
}
and for sure you need to implements your buttons using onClicklistener to be suitable for your idea.
https://www.youtube.com/watch?v=lkadcYQ6SuY&index=89&list=PL2F07DBCDCC01493A
https://www.youtube.com/watch?v=PQ94MmEg0Qw&index=90&list=PL2F07DBCDCC01493A

Android WebView setEmbeddedTitleBar problem

I'm trying to add a titlebar on WebView so the titlebar to be scrolled with WebView.
I used this code.
private void setEmbeddedTitleBar(WebView web, View titlebar) {
try {
Method m = WebView.class.getMethod("setEmbeddedTitleBar", new Class[] { View.class });
m.invoke(web, titlebar);
}
catch(Exception e) {
Log.d("TEST", "Err: "+e.toString());
}
}
I called the method above and the titlebar seemed to be added to the corresponding webview but the titlebar doesn't show up and just white space( height of titlebar ) is upside the webview content.
My classes are 'CTitleBar' , 'CTab' and 'CWebView'.
CTab includes CWebView as a member( for one WebView per a Tab ).
And CTitleBar includes CTabs array as a member.
Prorgam operates like below.
By clicking 'add tab' button, user add a tab.
Then CTab is created with CWebView in it.
The tab is added to CTab array in CTitleBar.
( ** IMPORTANT ** ) And the CTitleBar view is added as tab.webView's titlebar.
This means.. the titlebar is referenced by it's member's member( titlebar.tab.webview ).
It seems to be a cross reference I think.
I don't know if this causes the 'white space' problem.
Or am I just using the method invocation with worng way?
How can I solve it?
Somebody help me.

Categories

Resources