Top Menu

Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Sunday 26 November 2017

Circular Button with Icon and Text in Android

Rounded android button can be used for many purposes to make awesome application. We can see many applications that have used circle button or rounded corner. In this tutorial, I am going to show how to make circular android button and to add icons/images and text in the same button.

To make circular button in android app, you don’t need any java code, this can be done by using only XML. Rounded button can also be created by using java code but it is time consuming and need to have advance knowledge of java programming.

Here you will learn to make circular/rounded corner button using XML only.

Android Example: How to Create Circular Button with Icon and Text in Android


First you have to create a new XML file in drawable folder to make rounded button. In this file I have made a rectangle and gave border radius to make circular and fill the background and border color. Following is the complete content of XML drawable file.

res/drawable/ circle.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://pkrkinth.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="1000dp" />
<solid android:color="#41ba7a" />
<stroke
android:width="2dip"
android:color="#03ae3c" />
<padding
android:bottom="4dp"
android:left="4dp"
android:right="4dp"
android:top="4dp" />
</shape>
XML Layout File

This is the XML layout file where I have added different buttons with image and text together and set background to the drawable file that we have created above. Following is the complete content of XML layout file.

res/layout/circular_button_with_image_and_text.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://pkrkinth.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="16dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@drawable/circle"
android:drawableTop="@android:drawable/ic_dialog_email"
android:paddingTop="20dp"
android:text="Contact"
android:textColor="#fff" />
<Button
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginLeft="10dp"
android:background="@drawable/circle"
android:drawableTop="@android:drawable/ic_dialog_map"
android:paddingTop="20dp"
android:text="Map"
android:textColor="#fff" />
<Button
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginLeft="10dp"
android:background="@drawable/circle"
android:drawableTop="@android:drawable/ic_dialog_info"
android:paddingTop="20dp"
android:text="Info"
android:textColor="#fff" />
</LinearLayout>
</LinearLayout>

Java Activity File


Following is the default code of java activity file.

src/ RoundedAndroidButton.java
package pkrkinth.com.androidxmluserinterfacetutorial;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
public class RoundedAndroidButton extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.circular_button_with_image_and_text);
}
}

Strings.xml File


res/values/strings.xml
<resources>
<string name="app_name">Circular Button with Icon and Text</string>
</resources>

Now, run your Circular Button with Icon and Text in Android application which will look like above screenshot. If you have any question please mention in the comment box below. 
Read more...

Thursday 9 November 2017

"Geckodriver" execution issue while running Java application from Selenium Automation

You can get this issue most often while running Java application using Selenium IDE for automation testing. The issue look like this:

Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property; for more information, see https://github.com/mozilla/geckodriver. The latest version can be downloaded from https://github.com/mozilla/geckodriver/releases

The Selenium client bindings will try to locate the geckodriver executable from the system PATH. You will need to add the directory containing the executable to the system path.
  • On Unix systems you can do the following to append it to your system’s search path, if you’re using a bash-compatible shell:
    export PATH=$PATH:/path/to/geckodriver
  • On Windows you need to update the Path system variable to add the full directory path to the executable. The principle is the same as on Unix.
All below configuration for launching latest firefox using any programming language binding is applicable for Selenium2 to enable Marionette explicitly. With Selenium 3.0 and later, you shouldn't need to do anything to use Marionette, as it's enabled by default.
To use Marionette in your tests you will need to update your desired capabilities to use it.
Java :
As exception is clearly saying you need to download latest geckodriver.exe from here and set downloaded geckodriver.exe path where it's exists in your computer as system property with with variable webdriver.gecko.driver before initiating marionette driver and launching firefox as below :-
//if you didn't update the Path system variable to add the full directory path to the executable as above mentioned then doing this directly through code
System.setProperty("webdriver.gecko.driver", "path/to/geckodriver.exe");

//Now you can Initialize marionette driver to launch firefox
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
WebDriver driver = new MarionetteDriver(capabilities); 
And for Selenium3 use as :-
WebDriver driver = new FirefoxDriver();
Note : Just like the other drivers available to Selenium from other browser vendors, Mozilla has released now an executable that will run alongside the browser. Follow this for more details.

There is way to solve this issue

You are using latest version of Selenium WebDriver i.e. Selenium 3.x, this version of webdriver doesn't support direct firefox launch. You have to set the SystemProperty for webdriver.gecko.driver.
Replace the Code:-
WebDriver driver;
driver =new FirefoxDriver();
With This code:-
WebDriver driver;
System.setProperty("webdriver.gecko.driver", "<Path to your WebDriver>");
driver =new FirefoxDriver();
You can get the information about latest changes here
You can download the latest Gecko driver from here


Read more...