如果按下按钮,我会尝试切换按钮的背景.我建立了一个选择器,就像这里建议的答案:标准Android按钮具有不同的颜色
最后我想把GradientDrawables放在里面,但出于调试目的我只想设置一个颜色,看看它是否正常工作.这是我的选择器
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/red"/>
<item
android:state_focused="true"
android:drawable="@color/white"/>
<item
android:state_pressed="true"
android:drawable="@color/white"/>
</selector>
Run Code Online (Sandbox Code Playgroud)
不幸的是,这不起作用.我从我的按钮中将选择器设置为背景,并且只能看到它们的红色.我做错了什么(Build Target 2.1)
这是我的代码:
package com.testappmobile;
import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class testappmobileActivity extends Activity
{
final Activity activity = this;
private WebView webview;
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// Check if the key event was the BACK key and if there's history
if ((keyCode == KeyEvent.KEYCODE_BACK) && webview.canGoBack()) {
webview.goBack();
return true;
}
// If it wasn't the BACK key or there's no web page history, bubble up to …Run Code Online (Sandbox Code Playgroud) 所以我有这个代码,应该听#button的点击,但它不会工作,并让我疯了!
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript">
$('#button').click(function() {
alert('OK!');
});
</script>
Run Code Online (Sandbox Code Playgroud)
和HTML:
<input id="button" type="button" value="OK" />
Run Code Online (Sandbox Code Playgroud)
这很奇怪.欢迎任何帮助!
我有一个按钮,当这个按钮正在播放动画时,我无法点击按钮.我设置了单击侦听器和触摸侦听器,但在调试模式下,它没有进入OnClick和onTouch方法.你知道为什么吗?谢谢
编辑:我尝试过类似的东西:
AsyncTask task = new AsyncTask() {
@Override
protected Object doInBackground(Object... objects) {
button1.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Toast toast = Toast.makeText(MyActivity.this, button1.getText(), Toast.LENGTH_SHORT);
toast.show();
}
});
return null;
}
;
};
task.execute(button1);
Run Code Online (Sandbox Code Playgroud)
但它不起作用
编辑:这是完整的源代码
我有按钮,我使用旋转动画旋转了45度,并应用于烘焙消息的点击监听器.
当我点击上面50%的按钮吐司显示.但当我点击按钮的低50%时,没有任何东西在发生.
这里有动画代码.
<?xml version="1.0" encoding="utf-8"?>
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="45"
android:toDegrees="45"
android:pivotX="50%"
android:pivotY="50%"
android:duration="0" android:fillAfter="true">
</rotate>
Run Code Online (Sandbox Code Playgroud)

提前致谢.....!
我需要创建一个按钮,左边有一个图标,右边有一个文本.按下按钮后,我想在按钮左侧图标的位置看到旋转图像的动画.
我试图使用AnimationDrawable,但它也没有用,没有动画但只显示了第一个png文件.无论我使用什么背景或leftDrawable按钮来运行AnimationDrawable都是一样的.代码如下:
package com.example.layout;
import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.widget.Button;
public class TestLinearlayoutActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
public void onStart() {
super.onStart();
Button locationTitleButton = (Button) findViewById(R.id.LocationTitleButton);
//locationTitleButton.setBackgroundResource(R.drawable.loading);
locationTitleButton.setCompoundDrawablesWithIntrinsicBounds(R.drawable.loading, 0, 0, 0);
Drawable[] locationTitleButtonDrawables = locationTitleButton.getCompoundDrawables();
AnimationDrawable animDrawable = (AnimationDrawable) locationTitleButtonDrawables[0];
//AnimationDrawable animDrawable = (AnimationDrawable) locationTitleButton.getBackground();
animDrawable.start();
}
}
//loading.xml:
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item …Run Code Online (Sandbox Code Playgroud) 所以,我收到了这个错误
11-15 16:55:40.617: E/AndroidRuntime(316): java.lang.IllegalStateException: Could not find a method ingresarBtnClick(View) in the activity class android.view.ContextThemeWrapper for onClick handler on view class android.widget.Button with id 'ingresarButton'
Run Code Online (Sandbox Code Playgroud)
这是我的布局xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical" android:weightSum="1" android:id="@+id/Login">
<TextView android:layout_width="wrap_content" android:id="@+id/textView1" android:textAppearance="?android:attr/textAppearanceLarge" android:text="Número de Lecturista" android:layout_height="wrap_content"></TextView>
<EditText android:inputType="number" android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/numLecEditText" android:maxLength="4">
<requestFocus></requestFocus>
</EditText>
<TextView android:layout_width="wrap_content" android:id="@+id/textView2" android:textAppearance="?android:attr/textAppearanceLarge" android:layout_height="wrap_content" android:text="PIN"></TextView>
<EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="number" android:password="true" android:id="@+id/pinEditText" android:maxLength="4"></EditText>
<TableRow android:id="@+id/tableRow1" android:layout_width="match_parent" android:layout_height="wrap_content">
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Ingresar" android:id="@+id/ingresarButton" android:onClick="ingresarBtnClick"></Button>
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Salir" …Run Code Online (Sandbox Code Playgroud) 我意识到当我设置具有属性IsCancel = True的退出按钮时,窗口的关闭事件将触发两次.
private void exitButton_Click(object sender, RoutedEventArgs e)
{
// this button was set attribute IsCancel = True.
Close();
}
private void BaseWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
MessageBox.Show("test"); // this message box will show twice
// when you click on the exit button
e.Cancel = true;
}
Run Code Online (Sandbox Code Playgroud)
这是WPF的错误吗?有解决方法吗?
Ps:抱歉,我忘了说只有从父窗口调用窗口时才会出现此错误.
我在网格中有一个按钮,其中包含许多其他按钮和控件
<Grid IsEnabled="false">
<Grid.ColumnsDefinition>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnsDefinition>
<Button Content="Run"/>
<Button Grid.Column="1" Content="Test"/>
<Button Grid.Column="2" Content="Cancel" IsEnabled="true"/>
</Grid>
Run Code Online (Sandbox Code Playgroud)
如您所见,网格已禁用,但其中的取消按钮应启用.
我遇到的问题是,即使我将内部按钮设置为启用,它仍然处于禁用状态,可能是因为其父级已禁用.
有没有办法覆盖此行为并强制启用该按钮?
我正在使用它来处理在后台运行长进程的情况,因此应禁用除取消进程之外的所有UI操作.
谢谢!