我不确定这是否可能.我有这个按钮:
<Button
android:id="@+id/b1"
android:layout_width="wrap_content"
android:layout_height="45px"
android:drawableTop="@drawable/buttontv"
android:layout_weight="1"
android:background="@null"
android:textColor="#ffffff"
android:textSize="9px"
android:text="TV"/>
Run Code Online (Sandbox Code Playgroud)
这个按钮有这个项目xml:
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_focused="true"
android:state_pressed="false"
android:drawable="@drawable/tv" />
<item
android:state_focused="true"
android:state_pressed="true"
android:drawable="@drawable/tv_pressed" />
<item
android:state_focused="false"
android:state_pressed="true"
android:drawable="@drawable/tv_pressed" />
<item
android:drawable="@drawable/tv" />
</selector>
Run Code Online (Sandbox Code Playgroud)
在我的应用程序中,我在单击按钮时使用此代码:
OnClickListener b1Listener = new OnClickListener(){
@Override
public void onClick(View v) { loadUrl("http://example.org/"); v.setPressed(true); }
};
Button b1 = (Button) findViewById(R.id.b1);
b1.setOnClickListener(b1Listener);
Run Code Online (Sandbox Code Playgroud)
当我按下按钮时,我想要的是,drawableTop设置为具有@ drawable/tv_pressed属性值的项目之一 - 并保持在那里(如'这是当前活动按钮').
我尝试在onClick函数中添加v.setPressed(true)(因为这是我可以在Google上找到的所有内容),但这不起作用.
可以这样做吗?或者,有没有比我想要完成的更好的选择?
| 归档时间: |
|
| 查看次数: |
11200 次 |
| 最近记录: |