Visual studio, Xamarin, WebView - c#

I'm making application for android using Visual Studio and Xamarin but I have problem with WebView when I create a WebView and try to see it in android emulator i get an error:
Android.Views.InflateException: Binary XML file line #1: Error inflating class android.webkit.WebView
Anybody knows where is problem?
The Layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="schemas.android.com/apk/res/android";
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:minWidth="25px"
android:minHeight="25px">
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/webView1" />
</LinearLayout>

After trying out the Layout xml the compiler throws an error becouse of a semicolon at the end of xmlns:android="schemas.android.com/apk/res/android";. If you remove that the layout should build.
Another thing is that the url in xmlns:android attribute is missing http:// in front of the url. Without that the inflater doesn't understand the attributes correctly.
Here is a fixed Layout for you
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:minWidth="25px"
android:minHeight="25px">
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/webView1" />
</LinearLayout>

Related

Vertical tabLayout on Android (Xamarin)

Issue
Make a vertical tablayout but it uses more spaces than it need.
In addition, I want tabItem's text be horizonal.
I couldn't paste an image so I paste a link that I asked at other website.
She told me that make a vertical tab with tablayout is impossible.
Screen I want to make
First image is the display what I want to make. Second image is the display at now.
https://teratail.com/questions/0p99tlvnpzqpoj
Code
XML file
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--AppBar
#+id/appBar-->
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/appBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:expanded="false">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="46dp">
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
<!--Tab & Content-->
<LinearLayout
android:id="#+id/linLay_TabContent"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toTopOf="#+id/linLay_EventRep"
app:layout_constraintTop_toBottomOf="#+id/appBar">
<!--Tab & image
#+id/Tab-->
<LinearLayout
android:id="#+id/Tab"
android:layout_width="300dp"
android:layout_height="300dp"
android:rotation="-90"
app:layout_constraintEnd_toStartOf="#+id/Content"
android:orientation="vertical">
<com.google.android.material.tabs.TabLayout
android:id="#+id/tablayout"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
app:tabTextAppearance="#style/TabLayoutTextAppearance"
app:tabMinWidth="79dp"
app:tabMode="scrollable">
<com.google.android.material.tabs.TabItem
android:text="test1"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<com.google.android.material.tabs.TabItem
android:text="test2"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<com.google.android.material.tabs.TabItem
android:text="test3"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.tabs.TabLayout>
<ImageButton
android:id="#+id/image"
android:layout_width="60dp"
android:layout_height="match_parent"
android:layout_marginTop="1dp"
android:paddingTop="15dp"
android:paddingBottom="15dp"
android:paddingRight="19dp"
android:paddingLeft="17dp"/>
</LinearLayout>
<!--Content
#+id/Content-->
<LinearLayout
android:id="#+id/Content"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/Tab">
<TextView
android:id="#+id/txt1"
android:text="data"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/linLay_EventRep"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:layout_constraintBottom_toBottomOf="parent">
<TextView
android:id="#+id/txt1"
android:text="text1"
android:layout_width="78dp"
android:layout_height="48dp"
android:layout_gravity="bottom"/>
<TextView
android:id="#+id/txt2"
android:text="text2"
android:layout_width="78dp"
android:layout_height="48dp"
android:layout_gravity="bottom"/>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Version
Microsoft Visual Studio 2019 Version 16.11.19
Microsoft .NET Framework Version 4.8.04084
MonoAndroid, Version=v9.0
remarks
I checked this site but couldn't understand the meaning of code Setup in Code thus couldn't write with C#.
Vertical Android TabLayout not scroll vertically
I test the code you provided and link provided. Unfortunately, TabLayout can't achieve the effect you want. And here is my screenshot of test effect. As the second answer in the link said:
TabLayout provides a horizontal layout to display tabs.
You can choose this case's method.

How to put button, edittext etc below custom toolbar

I have created a custom toolbar. But when I put things like imageview, button etc it wont be below toolbar. I also tried android:layout_below but i either its not working or I put wrong id (i tried multiple ids). Its just mixing with the toolbar.
In the code the imageview is merging with the toolbar and i want the imageview to be below it.
Thanks for anyone who answers
code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar" />
<ImageView
android:id="#+id/icon"
android:layout_below="#id/toolbar"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:background="#drawable/shoppingcart"
android:layout_width="100dp"
android:layout_height="100dp"
/>
<android.support.design.widget.TextInputLayout
android:layout_below="#+id/icon"
android:id="#+id/forgot_input_email"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/forgot_email"
android:hint="Enter groceries"
android:inputType="textCapWords"
android:maxLines="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</android.support.design.widget.TextInputLayout>
P.s.
include is just the normal toolbar settings
I got my answer! I had to put on image view tag android:layout_marginTop="?attr/actionBarSize", it just do it below the height of the toolbar/actionbar Like that:
<ImageView
android:layout_marginTop="?attr/actionBarSize"
android:id="#+id/icon"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:background="#drawable/shoppingcart"
android:layout_width="100dp"
android:layout_height="100dp"

Xamarin - Image Not Displaying

I'm trying to display an image in my Xamarin app but it does not seem to be displaying on the screen. The app complies and runs without any warnings or errors, and a separate image is displaying successfully as a long toolbar along the top of the app.
The images are held within my Resources -> Drawable directory.
XAML
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:minWidth="25px"
android:minHeight="25px"
android:rowCount="5"
android:columnCount="2">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar"
android:layout_height="150px"
android:layout_width="match_parent" />
<ImageView
android:id="#+id/cardOne"
android:layout_width="wrap_content"
android:layout_height="150px"
android:src="#drawable/m1"
android:layout_row="3"
android:layout_column="1" />
</GridLayout>
MainActivity
var imageView = FindViewById<ImageView>(Resource.Id.cardOne);
imageView.SetImageResource(Resource.Drawable.m1);

Project build error in xamarin studio

While building project an error is shown and build getting failed.
Error redirects to axml file below:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:minWidth="25px"
android:minHeight="25px">
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/webView" />
</LinearLayout>
Error :
C:\Users\Documents\Projects\\\Resources\layout\Main.axml(1,1): Error CS0116:
A namespace cannot directly contain members such as fields or methods (CS0116)
(ABC)
Check the Build Action for the Main.axml file. It should be set to Android Resource but it sounds like it is set to Compile.
Right click the Main.axml file and use the Build Action menu to change this.

Android Layout issues.. Not sure how to debug

UPDATE____
Logcat output http://pastie.org/2039452
My application is stopping in the debugger, and then crashing on this line, but it is strange because it has no error information just a green arrow like so...
Any insight on what this arrow means in general would be appreciated...
Here is LayoutStudentList
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
>
<TextView
android:id="#+id/studentHeader"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:textSize="16sp"
android:text="#string/StudentListHeader"
android:layout_alignParentTop="true"
/>
<EditText
android:id="#+id/studentSearch"
android:layout_width="fill_parent"
android:layout_below="#id/studentHeader"
android:padding="10dp"
android:textSize="12sp"
android:editable="true"
android:hint="#string/StudentFilterPlaceholder"
/>
<ListView
android:id="#+id/studentListView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/studentSearch"
android:padding="10dp"
/>
</RelativeLayout>
The problem is almost definitely in my XML somewhere, as when I replace the layout contents with a single textview and set the text it works fine.
The problem is that the studentSearch EditText element in your layout file didn't specify a layout_height attribute. Once you add that in the problem should go away (I verified this locally as well). The error message and accompanying stacktrace would also be visible via the ADB logcat output:
I/dalvikvm( 2083): Ljava/lang/RuntimeException;: Binary XML file line #14: You must supply a layout_height attribute.
What does 'hanging' mean? Like, stopped in the debugger? Crashing?
Shouldn't that be setContentView(), not Set with a capital S? Maybe that's the problem.

Categories