Showing posts with label Android. Show all posts
Showing posts with label Android. Show all posts

Wednesday, 2 November 2022

Android XML

 

XML in Android: Basics And Different XML Files Used In Android

XML stands for Extensible Markup Language. XML is a markup language much like HTML used to describe data.  XML tags are not predefined in XML. We must define our own Tags. Xml as itself is well readable both by human and machine. Also, it is scalable and simple to develop. In Android we use xml for designing our layouts because xml is lightweight language so it doesn’t make our layout heavy.

In this article we will go through the basic concepts of xml in Android and different XML files used for different purpose in Android. This will help you in writing a UI code to design your desired user interface.

Basics Of User Interface:

The whole concept of Android User Interface is defined using the hierarchy of View and ViewGroup objects. A ViewGroup is an invisible container that organizes child views. These child views are other widgets which are used to make the different parts of UI. One ViewGroup can have another ViewGroup as an child element as shown in the figure given below:


Here in above Diagram ViewGroup (Linear Layout) contains one ViewGroup (i.e. Relative Layout)and two View(Button and TextView). Further two more View (i.e. 2 EditText ) are nested inside Relative Layout ViewGroup. It is important to note that one layout can be nested in another layout.

The below code snippet will explain the above image in better way. Paste it in activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical" android:layout_width="match_parent"
 android:layout_height="match_parent">


 <Button
 android:id="@+id/buton1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:text="Button"/>

 <TextView
 android:id="@+id/textView1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:text="sample Text"
 android:layout_marginTop="15dp"
 android:textSize="30dp"/>

 <RelativeLayout
 android:layout_width="match_parent"
 android:layout_height="match_parent">

 <EditText
 android:id="@+id/editTextName"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:hint="First Name"
 />

 <EditText
 android:id="@+id/editTextLastName"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:hint="Last Name"/>

 </RelativeLayout>
</LinearLayout>



Every Android application screen has some components like button, Text or images. These are contained inside the ViewGroup. Layouts are the best examples for ViewGroups. The different types of layout in android are Linear Layout, Relative Layout, Absolute Layout, Table Layout and Frame Layout.

Different XML Files Used in Android:

In Android there are several xml files used for several different purposes. Below we define each and every one.

1. Layout XML Files: Layout xml files are used to define the actual UI(User interface) of our application. It holds all the elements(views) or the tools that we want to use in our application. Like the TextView’s, Button’s and other UI elements.

Location in Android Studio:

You will find out this file inside the res folder and inside it there is another folder named layout where you will get all the layout files for their respective activities or fragments.


Basic Layout XML Code:

Below we show activity_main.xml file in which we have two TextView’s.

<!--  RelativeLayout in which we set green color for the background -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/greenColor"
tools:context=".MainActivity">

<TextView
android:id="@+id/firstTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_margin="20dp"
android:padding="10dp"
android:text="First Text View"
android:textColor="@color/white"
android:textSize="20sp"
android:textStyle="bold" />
<!-- second TextView -->
<TextView
android:id="@+id/secondTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/firstTextView"
android:layout_centerHorizontal="true"
android:layout_margin="20dp"
android:padding="10dp"
android:text="Second Text View"
android:textColor="@color/white"
android:textSize="20sp"
android:textStyle="bold" />

</RelativeLayout>

2. Manifest xml File(Mainfest.xml): This xml is used to define all the components of our application. It includes the names of our application packages, our Activities, receivers, services  and the permissions that our application needs. For Example – Suppose we need to use internet in our app then we need to define Internet permission in this file.

Location in Android Studio:

It is located inside app > manifests folder



Defining Internet Permission in AndroidManifest.xml

Below we show the AndroidManifest.xml file and define the Internet Permission in that file.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="example.abhiandroid.MyApplication">     <!-- application package name -->

<uses-permission android:name="ANDROID.PERMISSION.INTERNET" />
<!-- define Internet Permission -->
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">

<!-- add your Activities, Receivers, Services Names Here -->
<activity
android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>

3. Strings xml File(strings.xml): This xml file is used to replace the Hard-coded strings with a single string. We define all the strings in this xml file and then access them in our app(Activity or in  Layout XML files) from this file. This file enhance the reusability of the code.

Location in Android Studio:


Below we show strings.xml file and define a string in the file.

<resources>
<string name="app_name">My Application</string>

<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
<string name="login">User Login</string>
<!-- define your strings here -->
</resources>

4. Styles xml File(styles.xml): This xml is used to define different styles and looks for the UI(User Interface) of application. We define our custom themes and styles in this file.

Location in Android Studio:


Below we show the style.xml file.

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>

</resources>

5. Drawable xml Files: These are those xml files that are used to provide various graphics to the elements or views of application. When we need to create a custom UI we use drawable xml files. Suppose if we need to define a gradient color in the background of Button or any custom shape for a view then we create a Drawable xml file and set it in the background of View.


Below we show custom_drawable.xml file and create a gradient background color using style attribute.

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<!-- define start, center and end color for gradient -->
<gradient
android:centerColor="#0f0"
android:endColor="#00f"
android:startColor="#f00" />
</shape>

6. Color xml File (colors.xml): This file is used to define the color codes that we used in our app. We simply define the color’s in this file and used them in our app from this file.

Location in Android Studio


Below we show the colors.xml file in which we define green and white color.

<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- define your colors Here -->
<color name="greenColor">#0f0</color>
<color name="white">#fff</color>
</resources>

7. Dimension xml File(dimens.xml): This xml file is used to define the dimensions of the View’s. Suppose we need a Button with 50dp(density pixel) height then we define the value 50dp in dimens.xml file and then use it in our app from this file.

Location in Android Studio:

Below we show the dimens.xml file in which we define 50dp  dimension for Button height.

<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen><dimen name="btnheight">50dp</dimen>
</resources>


Android Programming with Eclipse IDE

Prerequisites For JAVA:

Eclipse:

Being a JAVA programmer you will need some tools or software to code and run it. Lots of tools are available over the web but we recommend you to use Eclipse for learning JAVA since it is the most common tool used for Android Development alongwith Android Studio. So getting habitual with Eclipse and its shortcuts will be bonus in your Android journey. Other then Eclipse you can also prefer IntelliJ or netbeans for learning JAVA.

Other Tools: IntelliJ and Netbeans

Android Studio? Are you thinking of using Android Studio for learning JAVA? Then Android Studio is solely meant for Android programming. IntelliJ, Eclipse and Netbeans are for real Java codings.

Android Studio is the official IDE (integrated development environment) for developing Android Apps by Google. It is based on  JetBrains’ IntelliJ IDEA software and has lots of amazing features which helps developer in creating Android App.

Android Studio is available for free download on Windows, Mac OS X and Linux.

Here we are going to share lots of guide, tips, tricks and shortcut of Android Studio to help developer easily understand the tool.

Eclipse Vs Android Studio

Android App Development is mostly done in two IDE i.e. Eclipse and Android Studio. Earlier Eclipse was the popular IDE but now Android Studio has taken over it. This is because Google has ended the support for Eclipse and now only focused on Android Studio. Google also recommended developer to import their Android projects and use Android Studio.

Prerequisites For Learning Android Studio:

There are two prerequisites for learning Android Studio tips:

System Requirement – First your system OS must be either Windows, Max OS X or Linux with below requirement:

  • Microsoft Windows 10/8.1/8/7/Vista/2003/XP (32 or 64 bit)
  • Mac OS X 10.8.5 or higher, up to 10.10 to up 10.10.2 up 10.10.3 on 10.10.5 (Yosemite)
  • GNOME or KDE or Unity desktop on Ubuntu or Fedora or GNU/Linux Debian
  • Minimum RAM: 2GB
  • Recommended RAM: 4GB
  • Disk Space: 500 MB disk space
  • Android SDK Space Reqirement: At least 1 GB for Android SDK, emulator system images, and caches
  • JDK: Java Development Kit (JDK) 7 or higher
  • Screen Resolution: 1280×800 minimum screen resolution
  • Prefer faster processor according to your budget

Thursday, 20 August 2015

qr ITS APPLICATIONS

QR codes Quick Response codes, are two-dimensional bar codes which when scanned with the camera of a mobile device such as an iPad, Android tablet or smartphone can transfer web links, text and email addresses amongst other digital content quickly and easily to users. Popular with advertisers and marketing companies, QR codes give readers an immediate opportunity to visit a website to find out more information about a range of facts, products and services.
For schools that have invested in iPads or tablets as learning tools or allow their students to bring in their own devices (BYOD), QR codes have proven to be a great timesaver for sharing links and distributing information en masse. Projecting large QR codes on a screen so they can be scanned from around the class makes it easy for students to access the same content on their own devices and interact with it individually instead of passively looking at the interactive whiteboard. Scanning also eliminates the possibility they may type in a URL incorrectly and waste time troubleshooting. Printing out multiple QR codes, cutting them up and putting them around the room, adding them to worksheets or including them in homework tasks can lend themselves to a variety of engaging activities which cater to students’ different learning styles.
There are various ways of creating QR codes. You can use sites such asqrcode.kaywa.com or qrstuff.com or apps like QR Code Maker and QRafter for iOS and QR Droid for Android. Adding Russel Tarr’s QR Coder bookmarklet allows you to create a QR code from your browser in one tap or click. Here are instructions on how to add it to Safari on the iPad. The app I would recommend for scanning QR codes isi-nigma as it is very quick and available on different platforms. If you are sent a QR code as an email attachment, you can save it to your device and use the Scan app foriOS and Android to read it.
Here are some more tips on using QR codes in the classroom.
  1. Take links from individual files or folders stored in cloud services such asDropboxGoogle DriveBox and Copy and share them using QR codes. Curate multimedia content with sites like Edcanvas and MentorMob then share them via a QR code.
  2. Make an audio recording using the Audioboo app or web service to promote oracy skills. Copy the URL it generates and add .mp3 on the end. Turn this into a QR code and scan it. The audio will play automatically as the URL has been turned into a direct download link. Please note there is now a QR code export option available from the original URL on the Audioboo website, but this “hack” version is slicker, because it removes the temptation for students to click on other links and check out other recordings on the site! Have a listen to this boo I recorded when I heard about this new feature. Students could use audio QR codes to support written assignments, displays, presentations and dialogues. As an alternative to a written comment, teachers could put audio QR codes in learners’ exercise books to summarize common mistakes. Watch this video to see a wonderful example of how Audioboo and QR codes are being used in a library context.
  3. Put QR codes on paper worksheets which link to video or audio content with accompanying questions to create an alternative type of comprehension exercise compared to a traditional reading text. If yourQR code links to a Google Form, you could ask your students to watch or listen to a multimedia clip and fill in the questions in the boxes you had created. All their answers would then be collated in a spreadsheet and by installing the action script Flubaroo you could have them automatically marked too. Check out this YouTube clip to find out more and read this guide by Dr Sarah Elaine Eaton on how to build Google Forms.
  4. Use SnipURL to shorten the URL you want to turn into a QR code as this then lets you change the longer web link your QR code forwards to, turning it into a dynamic QR code! This means you could, for example, create one QR code per class and update it each week with a new homework link. Check out this blog post for a step-by-step guide.
  5. Import your QR codes into the Sign Maker app so you can give them titles and details on how they should be used. Take a screenshot of the results and crop the images by editing them in the camera roll or using an app like Skitch. This is a great way of distinguishing one QR code from another.
  6. For iPad owners, create a screencast using the ShowMe app to explain a concept or process. Make the URL it generates private and turn this into a QR code. To download the video, use the free iBolt app and save to the Camera Roll so you can embed it into an eBook or edit in iMovie. Have a look at this Guardian article for an example.
  7. Share eBooks you’ve generated using apps such as Book Creator or My Story with the class by opening them in the Droplr app which automatically uploads them to your private account and copies the URL to the clipboard. Turn this URL into a QR code so it can be scanned and downloaded on to multiple iPads at the same time.
  8. Generate multiple QR codes by copying the formula in this Google Doc by Tammy Worcester.
  9. Create your QR codes with Snap.vu and track how many times they have been scanned.
  10. Create a QR code treasure hunt for use in or out of your classroom with this  QR Treasure Hunt Generator from Classtools.net. The advantage of text QR codes is that you don’t need to be connected to the internet to scan them, which gives you more flexibility on where the activity can take place.
With more and more schools encouraging the use of internet-enabled mobile devices in and out of the classroom, the use of QR codes makes sense as a way of speeding up the transfer of multimedia content, for facilitating personalised learning and for adding an air of mystery for students to what lies behind the black and white squares. If you have never created a QR code before, why not give it a try and think how it can enhance teaching and learning in your classroom.

Friday, 24 July 2015

Androidz

Solution for Android SDK Manager not opening in Windows 8


I have installed windows 8 in my laptop and tried to open ‘Android SDK Manager’. It was not open. By googling I found the solution as below. 

Solution:- Go to android-sdk folder what you had set path under windows->preference menu for android.
Edit android.bat file.
Find java_exe=
And in front of add Java.exe path like “C:\Program Files (x86)\Java\jdk1.6.0\bin\java.exe

Saturday, 4 July 2015

Xiaomi Mi Note price 

An amazing product is built from amazing components and once again Xiaomi is coming up with yet another excellent product – Xiaomi MI Note. In their Xiaomi Flagship Product Launch 2015 it was announced that there will be two devices coming up in the smartphone segment. Or to be precise in the phablet segment. This device is powered by a Snapdragon 801 2.5GHz processor having Adreno 330 GPU for its media intensive tasks. It has 3GB of RAM which is adequate to run applications without having to consider killing any apps from the memory in order to maintain smooth user experience. This device features a 3D curved Gorilla Glass 3 with metal frame. The device body is considered to be of top notch quality. Cheap plastic is always an embarrassment in case of flagship phones. May be because of this factor Xiaomi MI4 was not as much successful as Xiaomi MI3  but this note looks promising. The camera is not a big upgrade from their earlier flagship smartphones. A Sony 13MP camera with OIS is included which is capable of clicking decent images. A 4MP front snapper is there for some good quality selfies. The speakers are of good quality. The most important factor is battery backup. This device is packed with a powerful 3000mAh lithium-ion battery which takes advantage of the snapdragon’s Quick Charge 2.0 facility.
Xiaomi Mi Note price in India will be around Rs 25000 for 16GB variant and Rs 28000 for 64GB variant
Technical Specifications of Xiaomi Mi Note
  • Snapdragon 801 2.5GHz processor, Adreno 330 GPU, 3GB RAM
  • 5.7” Sharp/JDI Full HD display
  • 3D curved Gorilla Glass 3 with metal frame
  • Dual 4G SIM (micro/nano), Dual Standby
  • Sony 13MP camera f/2.0, Optical Image Stabilisation (OIS)
  • 4MP front camera with large 2-micron pixels
  • Hi-Fi audio system, 24-bit/192KHz lossless playback support
  • 3000mAh lithium-ion battery, Quick Charge 2.0
You can buy it by going to this link once it is available in flipkart.