TextView के साथ डिजिटल क्लॉक बनाना
यह उदाहरण दर्शाता है कि Android में TextView का उपयोग करके ब्लिंक एनिमेशन के साथ डिजिटल क्लॉक कैसे बनाई जाती है।
चरण 1: नया प्रोजेक्ट बनाएं
Android Studio में File → New Project पर जाएं और प्रोजेक्ट बनाएं।
चरण 2: लेआउट फ़ाइल (res/layout/activity_main.xml)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="https://schemas.android.com/apk/res/android"
xmlns:app="https://schemas.android.com/apk/res-auto"
xmlns:tools="https://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical"
android:gravity="center">
<TextView
android:id="@+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textStyle="bold"
android:textSize="50sp"
app:fontFamily="@font/orbitron" />
</LinearLayout>
नोट: @font/orbitron के लिए फॉन्ट फ़ाइल को res/font/ में रखें।
चरण 3: MainActivity.java
package com.example.myapp;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import androidx.appcompat.app.AppCompatActivity;
import android.widget.TextView;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
public class MainActivity extends AppCompatActivity {
TextView textview;
Handler handler = new Handler();
Runnable blinkRunnable;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textview = findViewById(R.id.textview);
updateTime();
startBlink();
}
private void updateTime() {
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss", Locale.getDefault());
textview.setText(sdf.format(new Date()));
// हर सेकंड समय अपडेट करें
handler.postDelayed(this::updateTime, 1000);
}
private void startBlink() {
blinkRunnable = new Runnable() {
@Override
public void run() {
if (textview.getVisibility() == View.VISIBLE) {
textview.setVisibility(View.INVISIBLE);
} else {
textview.setVisibility(View.VISIBLE);
}
// 550ms बाद फिर से ब्लिंक करें
handler.postDelayed(this, 550);
}
};
handler.post(blinkRunnable);
}
@Override
protected void onDestroy() {
super.onDestroy();
handler.removeCallbacksAndMessages(null); // लीक रोकें
}
}
ऐप चलाएं
डिवाइस कनेक्ट करें और ऐप चलाएं।

उपरोक्त क्लॉक में TextView हमेशा के लिए ब्लिंक करेगा। हैंडलर का उपयोग करके UI थ्रेड पर सुरक्षित अपडेट किया जाता है। onDestroy() में कॉलबैक हटाना मेमोरी लीक रोकता है।