我有这个ToggleButton
<ToggleButton
android:id="@+id/PlaymusicToggleButton"
android:layout_width="30dp"
android:layout_height="30dp"
android:textOn=""
android:textOff=""
android:layout_weight="0"
android:background="@drawable/mediabutton"
android:layout_marginRight="10dp"
android:layout_centerVertical="true" />
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:state_pressed="true" android:drawable="@drawable/b_st" /> //currently pressed turning the toggle on
<item android:state_pressed="true" android:drawable="@drawable/b_st" /> //currently pressed turning the toggle off
<item android:state_checked="true" android:drawable="@drawable/b_st" /> //not pressed default checked state
<item android:drawable="@drawable/b_pl" /> //default non-pressed non-checked
我试图从函数
更新已检查的值 private void UpdatePlayer(int _music){
if (_music== 0)
{
music.Playing = true;
//playmusicToggleButton.RequestLayout ();
playmusicToggleButton.Checked = true;
但我得到了这个奇怪的错误
[ResourceType] No package identifier when getting value for resource number 0x000000
并且UpdatePlayer的其余部分无法加载,这个错误是什么?
我已经在片段的开头定义了togglebutton
public class ControlPanel : ListFragment, SeekBar.IOnSeekBarChangeListener
{
ToggleButton playmusicToggleButton;
并且我在OnCreateView上为它分配了一个值
playmusicToggleButton = view.FindViewById<ToggleButton> (Resource.Id.PlaymusicToggleButton);
答案 0 :(得分:1)
尝试这样做:
playmusicToggleButton = (ToggleButton) findViewById(R.id.playmusicToggleButton);
playmusicToggleButton.setChecked(true);