在创建活动并在Android中向用户显示用户界面时,如何显示按钮?
答案 0 :(得分:1)
这应该没关系:
@Override
public void onStart(){
super.onStart();
Button button = (Button) findViewById(R.id.test_button);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Log.i(TAG, "Clicked");
}
});
// This will NOT trigger the onClickListener!
button.setPressed(true);
}
答案 1 :(得分:0)
您应该使用按钮选择器状态,如下面的代码,即(res / drawable / button.xml)
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/button_add_to_favorites_active">
</item>
<item android:state_focused="true" android:drawable="@drawable/button_add_to_favorites_active">
</item>
<item android:drawable="@drawable/button_add_to_favorites_active"> //Here set the drawable looks like pressed one.
</item>
</selector>