Computer >> कंप्यूटर ट्यूटोरियल >  >> प्रोग्रामिंग >> Android

Android के लिए सॉफ्ट कीबोर्ड कैसे विकसित करें?

यह उदाहरण एक बेसिक Android ऐप दर्शाता है जो EditText इनपुट को TextView में दिखाता है - वास्तविक सॉफ्ट कीबोर्ड विकास के लिए InputMethodService की आवश्यकता होती है।

चरण 1: नया प्रोजेक्ट बनाएं

Android Studio में File → New Project चुनें।

चरण 2: UI लेआउट

res/layout/activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="https://schemas.android.com/apk/res/android"
    xmlns:tools="https://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">
    <EditText
        android:id="@+id/editText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="50dp"/>
    <Button
        android:id="@+id/btnShow"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/editText"
        android:layout_centerInParent="true"
        android:layout_marginTop="5dp"
        android:onClick="ShowText"
        android:text="SHOW TEXT"/>
    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/btnShow"
        android:layout_centerInParent="true"
        android:layout_marginTop="10dp"
        android:textSize="16sp"
        android:textStyle="bold"/>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="Soft KeyBoard"
        android:textSize="24sp"
        android:textStyle="bold"/>
</RelativeLayout>

चरण 3: MainActivity लॉजिक

src/MainActivity.java:

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    EditText editText;
    TextView textView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        editText = findViewById(R.id.editText);
        textView = findViewById(R.id.textView);
    }

    public void ShowText(View view) {
        String newText = editText.getText().toString();
        textView.setText(newText);
    }
}

महत्वपूर्ण नोट

यह उदाहरण केवल टेक्स्ट इनपुट/आउटपुट दर्शाता है। वास्तविक कस्टम सॉफ्ट कीबोर्ड बनाने के लिए InputMethodService एक्सटेंड करें, KeyboardView उपयोग करें, और AndroidManifest.xml में android.permission.BIND_INPUT_METHOD अनुमति के साथ सर्विस घोषित करें।

  1. Android TextView में टेक्स्ट को जस्टिफाई कैसे करें? Android TextView में टेक्स्ट को जस्टिफाई कैसे करें?

    TextView में टेक्स्ट जस्टिफिकेशन Android 8.0 (API 26) से android:justificationMode=inter_word एट्रिब्यूट का उपयोग करके TextView में टेक्स्ट को जस्टिफाई (दोनों किनारों पर संरेखित) किया जा सकता है। चरण 1: नया प्रोजेक्ट बनाएं Android Studio में File → New Project चुनें (न्यूनतम API 26 या अधिक)। चरण 2

  1. Android पर कीबोर्ड कैसे बदलें? Android पर कीबोर्ड कैसे बदलें?

    अनुकूलन Android OS के उद्भव की रीढ़ है और एक ऐसी विशेषता है Android फोन पर डिफ़ॉल्ट या स्टॉक कीबोर्ड को बदलना। यह परिवर्तन फोन के ब्रांड की परवाह किए बिना किया जा सकता है जैसे Samsung, Google, Huawei, Xiaomi, आदि। अधिकांश स्टॉक कीबोर्ड अच्छे हैं, लेकिन कुछ उपयोगकर्ता आवश्यकताओं के लिए, एक उपयोगकर्ता

  1. बाहरी कीबोर्ड के बिना Android के लिए Wine का उपयोग कैसे करें बाहरी कीबोर्ड के बिना Android के लिए Wine का उपयोग कैसे करें

    उन उपकरणों की सूची में Android उपकरणों को जोड़ना जो Wine का उपयोग करके Windows प्रोग्राम चला सकते हैं, कई लोगों के लिए एक रोमांचक कदम है, जब तक कि आपको एहसास न हो कि आपको इसके काम करने के लिए एक बाहरी कीबोर्ड की आवश्यकता है। हालांकि, एक और समाधान है। Wine एक प्रोग्राम है जिसे किसी अन्य ऑपरेटिंग सिस