对不起,我的问题很愚蠢,但我是 android 编程的新手......
我想知道如何在我的应用程序布局中添加指示器。这个想法是添加一个开/关绿色 LED(指示已连接/未连接)。
我搜索了很多,但我没有找到任何东西......我开始认为没有指标之类的东西......
最佳答案
使用 ToggleButton 小部件
通过此链接:- http://developer.android.com/guide/topics/ui/controls/togglebutton.html
这就是你如何使用它:-
<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"/>
这就是您在 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
}
}
});
关于Android:如何在 xml 布局中添加开/关指示器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20803837/