Monday, 17 August 2015
Monday, 27 July 2015
How to Create Card View in Android
Step 1. Create New Project in you Android Studio named “CardViewDemo”
Step 2. Add “com.android.support:cardview-v7:21.0.+” compile dependencies to you project .
Step 3. Add below code to your activity_main
<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"
tools:context=".MainActivity"
android:gravity="center">
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/cardView1"
card_view:cardCornerRadius="4dp"
android:layout_margin="5dp"
android:gravity="center"
>
<TextView
android:layout_gravity="center"
android:text="CardView"
android:textSize="40sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</android.support.v7.widget.CardView>
</RelativeLayout>
Run your code and you can see TextView inside Card View.
For any query comment here.
Thank youThursday, 23 July 2015
Localization in Android app supporting all Indian Languages
Prerequisite : Needs Android Studio Setup.
Step 1. Create new Project called Localization Demo
Step 2. Go to activity_main and add following code
<LinearLayout 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:orientation="vertical"
tools:context=".MainActivity"
android:gravity="center">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="26sp"
android:text="Language"
android:id="@+id/textView1" />
<TextView
android:layout_marginTop="10dp"
android:text="@string/app_lang"
android:textSize="40sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView2"/>
</LinearLayout>
Step 3. Right Click on values folder, Go to New-> Values resource file
Enter filename as strings and choose Language option from Available qualifiers and then choose the language from right side. As I have create strings.xml for all Indian languages.
Step 4. Add following code in hindi(hi) string.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_lang">हिन्दी</string>
</resources>
Step 5. Add following code in Assamese(as) string.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_lang">অসমীয়া</string>
</resources>
Step 6. Add following code in Bihari(bh) string.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_lang">बिहारी</string>
</resources>
Step 7. Add following code in English(en) string.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_lang">English</string>
</resources>
Step 8. Add following code in Gujarati(gu) string.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_lang">ગુજરાતી</string>
</resources>
Step 9. Add following code in Kannada(kn) string.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_lang">ಕನ್ನಡ</string>
</resources>
Step 10. Add following code in Kashmiri(ks) string.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_lang">कॉशुर</string>
</resources>
Step 11. Add following code in Malayalam(ml) string.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_lang">മലയാà´³ം</string>
</resources>
Step 12. Add following code in Marathi(mr) string.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_lang">मराठी</string>
</resources>
Step 13. Add following code in Oriya(or) string.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_lang">ଓଡ଼ିଆ</string>
</resources>
Step 14. Add following code in Sanskrit(sa) string.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_lang">संस्कृत</string>
</resources>
Step 15. Add following code in Tamil(ta) string.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_lang">தமிà®´்</string>
</resources>
Step 16. Add following code in Telgu(te) string.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_lang">à°¤ెà°²ుà°—ు</string>
</resources>
Step 17. Add following code in Urdu(ur) string.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_lang">اُردُÙˆ</string>
</resources>
Step 18. After that add following code to your menu_main.xml. For providing language change access to user.
<menu 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" tools:context=".MainActivity">
<item android:id="@+id/action_assamese" android:title="Assamese"
android:orderInCategory="100" app:showAsAction="never" />
<item android:id="@+id/action_hindi" android:title="Hindi"
android:orderInCategory="100" app:showAsAction="never" />
<item android:id="@+id/action_bihari" android:title="Bihari"
android:orderInCategory="100" app:showAsAction="never" />
<item android:id="@+id/action_english" android:title="English"
android:orderInCategory="100" app:showAsAction="never" />
<item android:id="@+id/action_gujarati" android:title="Gujarati"
android:orderInCategory="100" app:showAsAction="never" />
<item android:id="@+id/action_kannada" android:title="Kannada"
android:orderInCategory="100" app:showAsAction="never" />
<item android:id="@+id/action_kashmiri" android:title="Kashmiri"
android:orderInCategory="100" app:showAsAction="never" />
<item android:id="@+id/action_malayalam" android:title="Malayalam"
android:orderInCategory="100" app:showAsAction="never" />
<item android:id="@+id/action_marathi" android:title="Marathi"
android:orderInCategory="100" app:showAsAction="never" />
<item android:id="@+id/action_oriya" android:title="Oriya"
android:orderInCategory="100" app:showAsAction="never" />
<item android:id="@+id/action_sanskrit" android:title="Sanskrit"
android:orderInCategory="100" app:showAsAction="never" />
<item android:id="@+id/action_tamil" android:title="Tamil"
android:orderInCategory="100" app:showAsAction="never" />
<item android:id="@+id/action_telgu" android:title="Telgu"
android:orderInCategory="100" app:showAsAction="never" />
<item android:id="@+id/action_urdu" android:title="Urdu"
android:orderInCategory="100" app:showAsAction="never" />
</menu>
Step 19. Add below code to your MainActivity
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
switch (id){
case R.id.action_assamese:
setLocale("as");
return true;
case R.id.action_bihari:
setLocale("bh");
return true;
case R.id.action_english:
setLocale("en");
return true;
case R.id.action_gujarati:
setLocale("gu");
return true;
case R.id.action_hindi:
setLocale("hi");
return true;
case R.id.action_kannada:
setLocale("kn");
return true;
case R.id.action_kashmiri:
setLocale("ks");
return true;
case R.id.action_malayalam:
setLocale("ml");
return true;
case R.id.action_marathi:
setLocale("mr");
return true;
case R.id.action_oriya:
setLocale("or");
return true;
case R.id.action_sanskrit:
setLocale("sa");
return true;
case R.id.action_tamil:
setLocale("ta");
return true;
case R.id.action_telgu:
setLocale("te");
return true;
case R.id.action_urdu:
setLocale("ur");
return true;
}
return super.onOptionsItemSelected(item);
}
public void setLocale(String lang) {
Locale myLocale = new Locale(lang);
Resources res = getResources();
DisplayMetrics dm = res.getDisplayMetrics();
Configuration conf = res.getConfiguration();
conf.locale = myLocale;
res.updateConfiguration(conf, dm);
Intent refresh = new Intent(this, MainActivity.class);
startActivity(refresh);
finish();
}
setLocale Method will set user selected language to your application
Now, Run your application. And enjoy all Indian language support to your application
Note: You can download sourcecode from gihub.
Note: You can download sourcecode from gihub.
Subscribe to:
Posts (Atom)