문제

Excuse me, for my very stupid question, but I'm a newbie in android programming...

I was wondering how to add an indicator in the layout of my application. The idea was to add an On/Off green led (to indicate Connected/NotConnected).

I searched a lot but i haven't found anything... ...I started to think that there are no things like indicators...

도움이 되었습니까?

해결책

use ToggleButton widget

Go through this link :- http://developer.android.com/guide/topics/ui/controls/togglebutton.html

This is how you use it :-

<ToggleButton 
android:id="@+id/togglebutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOn="Vibrate on"
android:textOff="Vibrate off"
android:onClick="onToggleClicked"/>

and this is how you write listener in activity :-

ToggleButton toggle = (ToggleButton) findViewById(R.id.togglebutton);
toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        if (isChecked) {
            // The toggle is enabled
        } else {
            // The toggle is disabled
        }
    }
});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top