Skip to main content

Posts

Showing posts from March, 2016

android - Circle shape in XML drawable file

activity_main.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/rl" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="16dp" tools:context=".MainActivity" android:background="#f0f7e7" > <!-- To get a circular shape, we need to apply the same value for width and height --> <Button android:id="@+id/btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Circular Shape" android:layout_centerInParent="true" android:background="@drawable/circle_shape" android:textColor="#fff" /> ...

android - Detect when WebView finish loading a URL

MainActivity.java package com.cfsuman.androidtutorials; import android.graphics.Bitmap; import android.os.Bundle; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.Button; import android.widget.TextView; import android.widget.Toast; import androidx.appcompat.app.AppCompatActivity; public class MainActivity extends AppCompatActivity { private MainActivity mContext; private WebView mWebView; private TextView mTextView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Get the context mContext = this; // Get the widgets reference from XML layout mWebView = findViewById(R.id.webView); mTextView = findViewById(R.id.textView); Button button = findViewById(R.i...

android - How to restart an Activity

MainActivity.java package com.cfsuman.androidtutorials; import android.content.Intent; import android.os.Bundle; import android.app.Activity; import android.widget.Button; import android.widget.TextView; import java.util.Random; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Get the widgets reference from XML layout Button buttonRestart = findViewById(R.id.buttonRestart); Button buttonRecreate = findViewById(R.id.buttonRecreate); TextView textView = findViewById(R.id.textView); // Set the TextView text with a random generated number textView.setText("Random number : " + new Random().nextInt(100)); // Set a click listener for restart Button widget buttonRestart.setOnClickListener(view -> { Intent intent = getIntent(); ...