我有一个像这样定义的ToggleButton:
<ToggleButton android:text="ToggleButton" android:id="@+id/toggle"
android:layout_height="wrap_content" android:layout_width="fill_parent"></ToggleButton>
Run Code Online (Sandbox Code Playgroud)
我想以编程方式更改其状态.我尝试使用setChecked和toggle方法,但这些都不适用于我的情况.
我有持续通知,当我的活动收到通知意图时,切换按钮应设置为不检查,但它不起作用.
我在活动上这样做onResume.代码正在执行,但ToggleButton的状态不会改变.
奇怪的是,如果我调用setChecked(false)活动,onCreate它会改变按钮的状态,但不会改变onResume.我错过了什么?
谢谢.
我正在编写一个需要选择屏幕区域的应用程序.我需要将光标更改为十字形,然后在用户选择上绘制一个矩形.我搜索的第一件事是如何操纵光标,我遇到了wxPython.使用wxPython我可以轻松地在带有面板的Frame上执行此操作,问题是我需要窗口是透明的,这样用户可以在选择所需区域时看到他的屏幕,但是如果我制作框架和面板对象透明一切都变得越来越糟糕
所以,我对任何解决方案持开放态度,要么使用wxPython,要么不使用它,因为我真的不知道我是否正确使用它.
我是Python的新手,我不是英语母语人士,所以如果你不明白的话,我很抱歉.
这就是我编码的内容
import wx
class SelectableFrame(wx.Frame):
c1 = None
c2 = None
def __init__(self, parent=None, id=-1, title=""):
wx.Frame.__init__(self, parent, id, title, size=wx.DisplaySize(), style=wx.TRANSPARENT_WINDOW)
self.panel = wx.Panel(self, size=self.GetSize(), style=wx.TRANSPARENT_WINDOW)
self.panel.Bind(wx.EVT_MOTION, self.OnMouseMove)
self.panel.Bind(wx.EVT_LEFT_DOWN, self.OnMouseDown)
self.panel.Bind(wx.EVT_LEFT_UP, self.OnMouseUp)
self.panel.Bind(wx.EVT_PAINT, self.OnPaint)
self.SetCursor(wx.StockCursor(wx.CURSOR_CROSS))
def OnMouseMove(self, event):
if event.Dragging() and event.LeftIsDown():
self.c2 = event.GetPosition()
self.Refresh()
def OnMouseDown(self, event):
self.c1 = event.GetPosition()
def OnMouseUp(self, event):
self.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))
def OnPaint(self, event):
if self.c1 is None or self.c2 is None: return
dc = wx.PaintDC(self.panel)
dc.SetPen(wx.Pen('red', 1))
dc.SetBrush(wx.Brush(wx.Color(0, 0, 0), …Run Code Online (Sandbox Code Playgroud) 我在preferences.xml中有这个
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<CheckBoxPreference
android:key="displayNotification"
android:title="Display notification"
/>
<ListPreference
android:entries="@array/languages"
android:key="language"
/>
</PreferenceScreen>
Run Code Online (Sandbox Code Playgroud)
PreferencesActivity.java,使用此xml的类
public class PreferencesActivity extends PreferenceActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.xml.preferences);
}
}
Run Code Online (Sandbox Code Playgroud)
我在清单中宣布它是这样的
<activity android:name="com.tellthetime.PreferencesActivity" />
Run Code Online (Sandbox Code Playgroud)
当我开始活动时,我得到一个未找到的类异常,我不明白.
05-17 00:35:13.633: ERROR/AndroidRuntime(212): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tellthetime/com.tellthetime.PreferencesActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class PreferenceScreen
05-17 00:35:13.633: ERROR/AndroidRuntime(212): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
05-17 00:35:13.633: ERROR/AndroidRuntime(212): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
05-17 00:35:13.633: ERROR/AndroidRuntime(212): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
05-17 00:35:13.633: ERROR/AndroidRuntime(212): …Run Code Online (Sandbox Code Playgroud)