我有一个按钮,我希望当我按下它时,它会保持按下状态(Froyo上的绿色).
有帮助吗?
mycodes_Button = (Button) findViewById(R.id.mycodes);
...
if (saved_Button.isPressed())
{
saved_Button.setFocusable(true);
}
Run Code Online (Sandbox Code Playgroud)
像这样的东西?
我想启动一个计时器,它在第一次按下按钮时开始,在释放按钮时结束(基本上我想测量按钮按下的时间长度).我将在这两个时间使用System.nanoTime()方法,然后从最后一个中减去初始数字,以获得按住按钮时经过的时间的度量.
(如果您对使用nanoTime()以外的其他方法有任何建议,或者其他一些方法来衡量按钮的按住时间,我也会对这些人开放.)
谢谢!安迪
有没有办法在按下按钮时将样式应用于按钮?
如果我在style.xml中有样式:
<resources>
<style name="test">
<item name="android:textStyle">bold</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
button.xml中的选择器:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/test_pressed"
style="@style/test"
android:state_pressed="true"/>
<item android:drawable="@drawable/test_focused"
android:state_focused="true"/>
<item android:drawable="@drawable/test_normal"/>
</selector>
Run Code Online (Sandbox Code Playgroud)
那么我如何在布局中引用button.xml?
<Button
...
android:???="button"/>
Run Code Online (Sandbox Code Playgroud)
谢谢!
我的布局中有一个WebView和一些按钮.我的WebView中有一个大标签.此应用程序用于编辑文本文件.这些按钮用于影响WebView中的textarea.当用户按下按钮(例如箭头按钮以移动文本视图)时,它会关闭键盘.我使用过toggleSoftInput,但这只是切换键盘显示与否.我希望按钮在按下按钮时停止隐藏软键盘.我没有发现我的具体问题.我搜索了好几个星期.任何人都知道如何阻止我的按钮隐藏Android上的软键盘?
我在我的程序中使用QPushButton().使用这些按钮,我可以旋转对象.到目前为止工作正常.唯一的问题是我必须多次单击才能进一步旋转对象.这有点烦人.只要我按下它并且物体将进一步旋转,按钮是否有可能保持按下状态.按下了函数(),但clicked()没有区别.
我正在尝试根据其状态更改TextView样式.我的styles.xml包含:
<style name="text_normal_ops">
<item name="android:gravity">left</item>
<item name="android:textColor">@color/text_usual_color</item>
<item name="android:textStyle">bold</item>
</style>
<style name="text_normal_ops_pressed">
<item name="android:gravity">left</item>
<item name="android:textColor">@color/text_pressed</item>
<item name="android:textStyle">bold</item>
</style>
Run Code Online (Sandbox Code Playgroud)
我的selector(text_ops.xml)定义为:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" style="@style/text_normal_ops_pressed" />
<item android:state_focused="true" style="@style/text_normal_ops_pressed" />
<item android:state_selected="true" style="@style/text_normal_ops_pressed" />
<item style="@style/text_normal_ops"/>
</selector>
Run Code Online (Sandbox Code Playgroud)
但是当我将它应用到我的textview(style="@drawable/text_ops")时,它不起作用.有小费吗?
谢谢
我需要能够检测在我的特定操作期间是否按下某个键(例如CTRL).我无权访问密钥监听器,也无法访问鼠标事件.我希望有一些类有一个类似"boolean isKeyPressed(keycode)"的方法.
有没有人在java中意识到这样的方法?
对于一些背景知识,我试图覆盖组件的默认拖放行为.默认情况下,根据DropTargetDragEvent的javadocs ,如果没有按下任何键修饰符,则它会在组件的支持操作列表中查找移动,然后查找副本,然后查找链接并在找到第一个后停止.
在我的应用程序中,我们支持复制和链接.根据javadoc,没有按下CTRL键,默认操作是复制.我们希望用户能够指定默认操作(允许他们设置最常用的操作),然后使用修改键强制使用特定操作.
如果我可以检测到按键状态,那么我可以强制执行此操作,但我看不到任何其他方式更改默认操作.
布莱恩,提前谢谢
我有button_focused,button_pressed和button_normal图像。当我按下按钮时,将button_pressed显示图像,并且与按钮按下有关的动作开始。
当我退出按下按钮时,操作继续,但是按钮返回到button_normal正在显示的图像。
如何button_pressed在整个操作期间将要显示的按钮图像设置为该图像,然后重置为该button_normal图像?
感谢您的时间
如何使按钮的大小在按下时稍微增大并在释放时再次减小?这是为了通过使用尺寸和不同的颜色来突出显示按下的按钮。
问候,琪琪
我遇到了一个问题,直到现在还找不到解决方案!我已经实现了一个带有多个键的自定义键盘。每个键都有一个背景图像。我想更改按键本身的背景颜色,如下面的原始键盘所示:
我不想预览,我想在按下键时更改键本身的背景颜色。这是我的文件:
键盘文件
<?xml version="1.0" encoding="UTF-8"?>
<android.inputmethodservice.KeyboardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/keyboard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:keyPreviewOffset="10dp"
android:keyPreviewLayout ="@layout/preview"
android:keyTextColor="@color/colorAccent"
android:keyBackground="@drawable/keybackground"
android:background="#881f2023"
/>
Run Code Online (Sandbox Code Playgroud)
密钥背景.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@drawable/cleanbuttonnormal" />
<item
android:state_pressed="true"
android:drawable="@drawable/cleandeactivate" />
<item
android:state_checkable="true"
android:drawable="@drawable/cleanbuttonnormal" />
<item
android:state_checkable="true"
android:state_pressed="true"
android:drawable="@drawable/cleandeactivate" />
<item
android:state_checkable="true"
android:state_checked="true"
android:drawable="@drawable/cleanbuttonnormal" />
<item
android:state_checkable="true"
android:state_checked="true"
android:state_pressed="true"
android:drawable="@drawable/keybackground" />
</selector>
Run Code Online (Sandbox Code Playgroud)
背景颜色将更改为我的可绘制对象,但是当我按下键时,它不会更改为按下 - 状态。背景保持不变。请你帮助我好吗?
这是我的自定义键盘布局,启用预览以显示按钮被点击。
带有 8 的黑色按钮应该变成黄色。预览用于调试目的。