我的ObservableBoolean活动类中有一个字段,它绑定到我ToggleButton喜欢的"checked"属性:
android:checked="@{activity.editing}"
Run Code Online (Sandbox Code Playgroud)
我希望这会在按钮和布尔值之间创建双向关系,但它只会从字段到按钮进行更改,而不是相反.我做错了什么,或者这不在Android的范围内DataBinding?
我有一个带有ToggleButton(ExpanderButton)的TreeView.togglebutton有两个图像(一个用于展开,一个用于展开).然而,当我选择一个TreeViewItem时,我用不同的颜色高亮一点,我也想改变图像的颜色(我在另一种颜色中有相同的颜色).
问题是我不知道如何在ToggleButton上将触发器属性设置为TreeViewItem上的IsSelected属性.
有任何想法吗?
我试图从用户界面级别做一些看似相对简单和逻辑的东西,但我有一个非常烦人的错误.我有一个ToggleButton,我试图显示一个Popup按钮切换时,并隐藏Popup按钮切换时.在Popup当用户点击远离它也隐藏了.
一切都按照预期的方式使用以下XAML,除非在显示后单击切换按钮Popup,Popup消失一瞬间然后重新出现.
我怀疑这里发生了什么,点击远离Popup它是导致它关闭按钮然后立即切换按钮,因为鼠标点击它.我只是不知道如何修复它.
任何帮助表示赞赏.谢谢.
<ToggleButton x:Name="TogglePopupButton" Content="My Popup Toggle Button" Width="100" />
<Popup StaysOpen="False" IsOpen="{Binding IsChecked, ElementName=TogglePopupButton, Mode=TwoWay}">
<Border Width="100" Height="200" Background="White" BorderThickness="1" BorderBrush="Black">
<TextBlock>This is a test</TextBlock>
</Border>
</Popup>
Run Code Online (Sandbox Code Playgroud) 在我一直在努力的应用程序中,我希望有一个多状态(在我的情况下,三个)切换按钮,而不是提供的两个ToggleButton.我已经尝试Button按照CompoundButton源代码开始扩展自己,但老实说,阅读它的来源有点压倒性.
有没有办法只使用选择器xml或其他东西做一个三态切换按钮,或者可能是另一种我没想过的方法?我不知道该怎么做.
要创建自定义ToggleButton,我在以下位置定义了一个新样式/res/values/styles.xml:
<style name="myToggleButton">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textColor">#000000</item>
<item name="android:background">@drawable/my_toggle_button</item>
</style>
Run Code Online (Sandbox Code Playgroud)
然后我使用选择器指定按钮状态的外观/res/drawable/my_toggle_button.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true">
<shape>
[...]
</shape>
</item>
<item android:state_checked="false"
<shape>
[...]
</shape>
</item>
</selector>
Run Code Online (Sandbox Code Playgroud)
当状态发生变化时,如何修改此设置以切换按钮的文本颜色?
我需要能够访问一个ToggleButton看到的状态是如何没有办法为特定的状态创建方法ToggleButton.所以这就是我到目前为止的地方:
ToggleButton syncSwitch = (ToggleButton)findViewById(R.id.toggleButton1);
syncSwitch.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View view){
Toast.makeText(getApplicationContext(), "Click!", Toast.LENGTH_SHORT).show();
}
});
Run Code Online (Sandbox Code Playgroud)
现在我需要的是某种类型的布尔方法,它可以告诉处理程序状态ToggleButton.
我ToggleButton在WPF窗口中使用a :
<ToggleButton Height="37"
HorizontalAlignment="Left"
Margin="485.738,254.419,0,0"
VerticalAlignment="Top"
Width="109"
IsEnabled="True"
Checked="toggleAPDTimeoutErr_Checked"
Unchecked="toggleAPDTimeoutErr_Unchecked">Timeout</ToggleButton>
Run Code Online (Sandbox Code Playgroud)
我有两个正在监视的事件,但这是在处理程序后面的两个不同代码中完成的.怎么能只用一个呢?
我会有很多ToggleButton,代码可以变大.
我只是浏览源代码,寻找一种方法来做到这一点,但没有看到任何.我想确定,因为我可能错过了一些东西.是否有内置方式,就像方法一样?当我将一些ToggleButton组合在一起时,我希望能够获得当前所选(state == 'down')按钮的值(我猜的文本值).我知道我可以毫不费力地按照自己的方式来做这件事,但它似乎并不存在,这似乎很奇怪.
在检查了文档和源代码之后,我发现这是迄今为止最简单的方法:
from kivy.uix.togglebutton import ToggleButton as TB
current = [t for t in TB.get_widgets('group') if t.state=='down'][0]
value = current.text
Run Code Online (Sandbox Code Playgroud)
虽然这不是很长或很难做,但能够做到这样的事情会很好:
警告:虚构代码
value = TB.get_widgets('group').selected
Run Code Online (Sandbox Code Playgroud) 我有一个ToggleButton设置如下:
final ToggleButton filterButton = (ToggleButton) findViewById(R.id.filterTags);
filterButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (filterButton.isChecked()) {
// pop up the list of tags so the user can choose which to filter by
// once one is chosen, the spinner will be updated appropriately
showDialog(DIALOG_TAGS);
} else {
// going unpressed, set the the spinner list to everything
updateSpinner(db.itemNames());
}
}
});
Run Code Online (Sandbox Code Playgroud)
对话框如下所示:
case DIALOG_TAGS:
final String[] tagNames = db.tagNamesInUse();
dialog = new AlertDialog.Builder(this)
.setItems(tagNames, new DialogInterface.OnClickListener() {
public …Run Code Online (Sandbox Code Playgroud) 在android Toggle buttons中看起来像下面 -

我们可以将其修改为Iphone如下所示的样式 -

并且,我们是否可以包括切换按钮的iphone功能,如拖动切换功能.
如何完成此操作?提前致谢.