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 Activity

Android Activity Activity life cycle in Hindi Starting an  android activity in Hindi Creating a new activity in Hindi Destroying an  android activity in Hindi Introduction to Activity आप की application में एक से ज्यादा activity हो सकती है। जब आप इन activities के through navigate करते है, यानि एक activity से दूसरी activity में जाते है तो activity अपनी life cycle की different stages में जाती है। उदाहरण के लिए जब आपकी activity start होती है तो ये foreground में होती है और user का पूरा focus इस पर होता है। इस process के दौरान  android  system कुछ life cycle methods को call करता है। यदि user कोई दूसरी activity start करता है तो android system उस activity के life cycle methods को call करता है और आपकी पहले वाली activity background में चली जाती है। life cycle methods में आप decide कर सकते है की जब user जाता है या वापस आता है तो आपकी activity कैसे behave करेगी।  उदाहरण के लिए यदि आप एक वीडियो player बना रहे है तो जब user किसी दूसरी activity पर जाये तो...

Android Spinners

Android Spinners  Introduction to  android spinners in Hindi Defining  android spinners in Hindi Creating spinner items array in Hindi Responding to spinner selections in Hindi    Introduction to Android Spinners Android spinners आपकी एप्लीकेशन में एक drop down menu होती है। इस drop down menu में बहुत से items होते है जिन्हे user choices कहते है। जब user spinner पर क्लिक करता है तो ये items शो होते है। यूज़र अपने लिए appropriate choice choose करता है। By default spinner में सबसे top वाला element शो होता है। Spinners को XML layout file में क्रिएट किया जाता है। और items की लिस्ट string resource file में क्रिएट की जाती है। जिसमे आप एक string array क्रिएट करते है।  Spinner और items को जोड़ने के लिए एक array adapter क्रिएट किया जाता है। इसके बाद selection events को respond करने के लिए OnItemSelectedListener interface को  इम्प्लीमेंट किया जाता है।  Defining Android Spinners Android spinners को आप XML l...