I am very new to Android programming and I am trying to develop a small app that basically has four buttons. One of the buttons is suppose to take the user to a login page on a website (in the android app) when clicked.
I don't know what I am doing wrong but when ever the button (login) is clicked, the app crashes. Below are my codes
MAIN ACTIVITY XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:background="@drawable/back"
android:orientation="vertical"
tools:context=".MainActivity">
<Button
android:id="@+id/login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_margin="0dp"
android:alpha="0.6"
android:background="@drawable/my_button_bg"
android:drawableLeft="@drawable/ic_lock_open_black_24dp"
android:drawablePadding="5dp"
android:onClick="login"
android:padding="15dp"
android:paddingLeft="50dp"
android:paddingRight="20dp"
android:text="@string/text_login"
android:textAlignment="textStart"
android:textAllCaps="false"
android:textColor="@color/colorOrange"
android:textSize="20sp"
android:textStyle="bold"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="0dp"
android:layout_gravity="start"
android:textStyle="bold"
android:textAllCaps="false"
android:padding="15dp"
android:textSize="20sp"
android:textAlignment="textStart"
android:text="@string/text_howto"
android:id="@+id/howto"
android:alpha="0.6"
android:drawablePadding="5dp"
android:paddingLeft="50dp"
android:paddingRight="20dp"
android:background="@drawable/my_button_bg"
android:textColor="@color/colorOrange"
android:drawableLeft="@drawable/ic_live_help_black_24dp"
/>
MAIN ACTIVITY JAVA
package com.example.hp.fruitprint;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends AppCompatActivity {
private WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void login(View v) {
webView = (WebView)findViewById(R.id.home);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.loadUrl("https://mysitename.com/login");
webView.setWebViewClient(new WebViewClient());
}
}
APP (ACTIVITY) XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
tools:context=".MainActivity">
<WebView
android:id="@+id/home"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp"/>
</LinearLayout>
MANIFEST XML
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hp.fruitprint">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I know I am not doing something right but I am very very new to Android programming (started three days ago). Please also if you find anything at all I am not doing proper in the codes.