Skip to main content

Android Buttons

Android Buttons


  • Introduction to android buttons in Hindi
  • Steps to create android buttons in Hindi
  • Creating android buttons in Hindi 
  • Designing android buttons in Hindi     

Introduction to Android Buttons 

Buttons किसी भी एप्लीकेशन के लिए बहुत important element होते है। Button को click करने पर button कोई action perform करता है। इसके लिए आपको button की coding करनी होती है। 

हर button का एक नाम होता है। Android buttons के लिए आप नाम की जगह कोई icon भी यूज़ कर सकते है। Android buttons का एक साथ नाम भी हो सकता है और icon भी।

Android buttons editable होते है। Android buttons को styling बनाया जा सकता है। इसके लिए आप different styles और themes यूज़ कर सकते है। 

Button पर click होते ही onClick event occur होता है। हम इस event को handle करने के लिए coding करते है।         


Steps to Create Android Buttons

  1. सबसे पहले आप activity_main.xml file में button add करते है। 
  2. इसके बाद आप MainActivity.java file में button के click event की coding करते है। ये coding आप 2 तरह से कर सकते है।  


Creating Android Buttons 


Adding Button to XML File 

Button का यूजर इंटरफ़ेस XML file में क्रिएट किया जाता है। इसके लिए आप <Button> element यूज़ करते है। <Button> एलिमेंट के कुछ attributes होते है, जो निचे दिए जा रहे है। 

Android : layout_width - इस attribute के द्वारा आप button की width set कर सकते है। 

Android : layout_height - इस attribute से आप button की height सेट करते है। 

Android : text = "string" - इस attribute के द्वारा आप button का नाम देते है।  

Android : src = "@drawable/button_icon" - इस attribute के द्वारा आप button के icon को सेट करते है। 

Example


<Button
Android:layout_width="width of button"
Android:layout_height="height of button"
Android:text="name of button"
Android:src="icon of button" />


Handling onClick Event   

onClick event आप 2 तरह से handle कर सकते है। पहले तरीके में आप <Button> element का android:onClick attribute यूज़ करते है। इस तरीके में आप activity class में एक method क्रिएट करते है। ये method button के क्लिक होने पर कॉल होता है। इस method का नाम आप android:onClick attribute में पास करते है।

Example

In XML file


<Button
android:layout_width="width of button"
android:layout_height="height of button"
android:text="name of button"
android:onClick="yourMethod" />


In your activity class


public void yourMethod(View view)
{
    // perform your task here 
} 



जब यूज़र button पर click करता है तो onClick attribute में define किया हुआ method कॉल हो जाता है।

दूसरे तरीके में आप XML यूज़ नहीं करते है। ये तरीका run time में events handle करने के लिए उपयोगी होता है। इस तरीके में आप एक button object क्रिएट करते है। और उस button object पर setOnClickListener() मेथड कॉल करते है  और onClickListener सेट करते है।

यदि आप run time में event handle करना चाहते है तो ये तरीका यूज़ कर सकते है। XML file के द्वारा button क्रिएट करना सबसे easy होता है।

Designing Android Buttons      

अलग अलग devices अलग अलग styles यूज़ करते है। इसलिए आपके buttons अलग अलग devices पर अलग अलग styles में शो होते है। आप अपने buttons के style को control कर सकते है। इसके लिए आप पूरी एप्लीकेशन पर एक theme apply करते है।

Android आपको android:theme attribute provide करता है। इस attribute को आप <application> element में apply करते है। ये element AndroidManifest.xml फाइल में declared होता है।      


यदि आप buttons को individually configure करना चाहते है तो आप android:background attribute यूज़ कर सकते है। इस attribute में आप कोई image भी पास कर सकते है और कोई कलर भी पास कर सकते है। 

Comments

Popular posts from this blog

Android Services

Android Services Introduction to  android services in Hindi  Declaring  services in Hindi Creating a  android service in Hindi Introduction to Android Services इससे पहले की आप जाने की service क्या होती है आइये जानते है की service क्या नहीं होती है - एक service separate प्रोसेस नहीं होती है। ये आपकी एप्लीकेशन का ही पार्ट होती है।  एक service thread नहीं होती है।  आइये अब देखते है service क्या होती है - Service एक facility होती है जिससे आप android system को बता सकते है की आप कोई काम background में करते रहना चाहते है।  Service एक facility होती है जिससे एक एप्लीकेशन अपनी कुछ functionality दूसरी applications को expose कर सकती है।    हर service क्लास का <service> declaration AndroidManifest.xml file में होना चाहिए। Services को आप context.startService() और context.bindService() मेथड्स से स्टार्ट कर सकते है।            जब service component क्रिएट होता है तो android syst...

Android Fragments

Android Fragments Introduction to android fragments in Hindi Android fragments life cycle in Hindi Types of android fragments in Hindi Creating android fragment in Hindi Introduction to Android Fragments एक fragment किसी activity के अंदर एक separate UI (user interface) होता है। Fragments की खुद की life cycle और input events होते है। आप एक fragment को कई activities में use कर सकते है। जब आपकी activity running state में हो तब भी आप fragments को add और remove कर सकते है। Fragments को आप sub activity भी कह सकते है।   Android fragments को android के Honeycomb version में introduce किया गया था।  Android fragments से पहले आप user को एक बार में एक activity ही show कर सकते थे इसलिए आप स्क्रीन को अलग अलग parts में divide नहीं कर सकते थे। Fragments के आने से application design और भी ज्यादा flexible हो गयी क्योंकि आप यूजर को एक साथ एक से ज्यादा interface शो कर सकते है और उन्हें separately manage भी कर सकते है। अब आपके पास activity तो एक ही रहेगी लेकिन आप इसमें ब...

Android Development Tools

Android Development Tools  Android SDK in Hindi  Android Debug bridge in Hindi Android gradle in Hindi Android studio in Hindi Android run time and delvik in Hindi  Android SDK  Android SDK (Software Development Kit) -  Android SDK  में वो सभी टूल्स होते है जिनकी आपको एंड्राइड एप्लीकेशन क्रिएट करने में, कम्पाइल करने में और एप्लीकेशन को पैकेज करने के लिए जरुरत पड़ेगी।  Android SDK में आपको सोर्स कोड के साथ सैंपल प्रोजेक्ट्स, डेवलपमेंट टूल्स, एक इमुलेटर और एप्लीकेशन डेवेलप करने के लिए रिक्वायर्ड लाइब्रेरीज मिलती है। सभी एप्लीकेशन java में डेवेलप की जाती है और डेलविक वर्चुअल मशीन पर रन की जाती है। Android debug bridge  ADB  (Android Debug Bridge  ) - ADB android SDK का एक कमांड लाइन  टूल है जिसकी मदद से आप अपनी एप्लीकेशन को वर्चुअल डिवाइस या किसी रियल डिवाइस पर रन करवा सकते है और डिबग कर सकते है। ये एक क्लाइंट सर्वर प्रोग्राम होता है जिसमे एक क्लाइंट होता है, एक सर्वर...