Skip to main content

Posts

Add custom font in Android using Calligraphy library

Are you fed up of Custom Views to set fonts? Or traversing the ViewTree to find TextViews? Sometime we want some other font for our Android application then you can add custom font in Android using Calligraphy library . Dependency Include the dependency Download (.aar) dependencies { compile ‘uk.co.chrisjenx:calligraphy:2.2.0’ } Add Fonts Add your custom fonts to assets/ . All font definitions are relative to this path. On Assets you should right-click New Directory, call it "fonts". In the finder put the .ttf  or .otf  font files in there. Create Class Create a class that extends Application and write this code public class App extends Application { @Override public void onCreate() { super.onCreate(); CalligraphyConfig.initDefault(new CalligraphyConfig.Builder() .setDefaultFontPath("your font path") .setFontAttrId(

Android Collapsing ToolbarLayout Example

Android CollapsingToolbarLayout is a wrapper for Toolbar which implements a collapsing app bar. It is designed to be used as a direct child of a AppBarLayout. CollapsingToolbarLayout is the newly introduced in Lollipop , using which you can create awesome scrolling effect. The following sample will explain you how to achieve this CollapsingToolbarLayout Build Gradle file : build.gradle dependencies {     compile 'com.android.support:design:23.0.1'    compile 'de.hdodenhof:circleimageview:2.2.0' }   XML Layout activity_main.xml <? xml version= "1.0" encoding= "utf-8" ?> < android.support.design.widget.CoordinatorLayout xmlns: android = "http://schemas.android.com/apk/res/android"     xmlns: app = "http://schemas.android.com/apk/res-auto"     android :layout_width= "match_parent"     android :layout_height= "match_parent"     android :background= "@color/color_g

Disabling screen shot capture in Android application

In this tutorial we are going to show how to protect your application from screen shot capturing. Some applications might be having sensitive personal data (for example all banking applications), so as a developer we need to disable the option to take screen shot using DDMS console. See following steps : Use WindowManager.LayoutParams.FLAG_SECURE before setContentView() mehtod Note: There is no application level protection. You have to add this code in all the activities that you want to protect. Generally, when you take a screenshot, you will see a “Screen Capture” notification in the notification bar and you can see that screenshot in the Gallery app if you click that notification. Now, if you use FLAG_SECURE, the Notification will be “Can’t take screenshot…….” as below, Do as follow, In your Activity.Java import android.view.WindowManager; public class MainActivity extends AppCompatActivity { @Override public void onCreate(Bundle savedInstanceState) {