问题:
Android: couldn't save which view has focus because the focused view ### has no id
可能引起原因有两种,对应解决方法如下:
解决方案一:
<application
android:icon="@drawable/icon" android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:configChanges="orientation|keyboardHidden|keyboard|screenLayout"
android:name=".Main" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
解决方案二:
What probably happened is that you created a thread in the surfaceCreated() method but didn’t stop it or get rid of it in the surfaceDestroy() method.
When you didn’t give a theme for the preferences, it took over the whole screen and your old surface was destroyed. But when you specified a dialog-like theme, the old surface was still there because it was visible underneath the preferences.
public void surfaceCreated(SurfaceHolder holder)
{
if (_thread == null ||_thread.getState() == Thread.State.TERMINATED)
{
_thread = new TutorialThread(getHolder(), this);
_thread.setRunning(true);
_thread.start();
}
else
{
_thread.setRunning(true);
_thread.start();
}
}
This solved the problem for me, a thread’s start method cannot be called twice, so I had to reallocate…
http://forums.pragprog.com/forums/138/topics/4085
分享到:
相关推荐
android:id="@+id/list_view" android:layout_width="match_parent" android:layout_height="match_parent" android:listSelector="@drawable/your_selector" /> ``` 这里`@drawable/your_selector` 就是指向...
<item android:state_focused="true" android:drawable="@drawable/button_focused" /> <!-- 获得焦点状态 --> <item android:drawable="@drawable/button_normal" /> <!-- 默认状态 --> ``` 最后,...
public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { myButton.setScaleX(1.3f); myButton.setScaleY(1.3f); } else { myButton.setScaleX(1.0f); myButton.setScaleY(1.0f); } } }); ...
<item android:state_focused="true" android:drawable="@drawable/button_focused" /> <!-- 获得焦点状态 --> <item android:drawable="@drawable/button_normal" /> <!-- 默认状态 --> ``` 将此选择器设置为...
<item android:color="@color/focused_text_color" android:state_focused="true"/> ``` 然后在`TextView`的`android:textColor`属性中引用这个颜色选择器: ```xml android:id="@+id/textView" android:...
在 Android 中,按钮通常有三个状态:正常状态(normal)、焦点状态(focus)和按下状态(pressed)。为了实现这些状态,我们可以在 res/drawable 目录下定义一个资源文件,例如 handle.xml。在这个文件中,我们可以...
public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { // 当获取焦点时,启动动画 animation = AnimationUtils.loadAnimation(context, R.anim.zoom_in); imageView.startAnimation...
android:id="@+id/myButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="点击我" /> ``` 要添加动态效果,我们可以利用Android的属性动画系统。例如,当我们...
在Android开发中,自定义View和自定义Button是提升应用界面独特性和交互体验的重要手段。本Demo主要展示了如何通过自定义View和自定义Button来实现特定的视觉效果和交互功能,比如Button在被点击时变换背景。下面...
<item android:drawable="@drawable/icon_focused" android:state_focused="true" /> <item android:drawable="@drawable/icon_normal" /> ``` #### `<shape>`: 形状 **描述**:`<shape>`提供了一种基本的方法...
<Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/button_style" /> ``` 使用 XML 文件定义不同的样式实现自定义 ...
<item android:state_focused="true" android:drawable="@drawable/button_focused"/> <item android:state_pressed="true" android:drawable="@drawable/button_pressed"/> <item android:drawable="@drawable/...
我们还可以把描边弄成虚线的形式,设置方式为:android:dashWidth="5dp" android:dashGap="3dp",其中 android:dashWidth 表示 '-' 这样一个横线的宽度,android:dashGap 表示之间隔开的距离。 Corners:圆角。...
<item android:state_focused="true" android:drawable="@drawable/focus"/> <item android:state_selected="true" android:drawable="@drawable/selected"/> <item android:drawable="@drawable/surprise"/> ``...
android:id="@+id/btSecond" android:background="@drawable/button_test2" android:layout_marginTop="15dip" android:text="@string/calculate" android:ellipsize="marquee" android:gravity="center" ...
android:id="@+id/my_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/button_selector" android:text="点击我" /> ``` 在这里,`android:...
android:id="@+id/my_list_view" android:listSelector="@drawable/list_item_bg" /> ``` 2. **在Java代码中设置**: ```java ListView listView = (ListView) findViewById(R.id.my_list_view); Drawable ...
1. `Drawable`缓存:Android系统会自动缓存`Drawable`,但过度的缓存可能导致内存泄漏。因此,当不再需要`Drawable`时,需要调用`setCallback(null)`释放引用。 2. 位图压缩:对于大图,可以使用WebP等压缩格式减少...
将Shape定义为XML资源文件后,可以在布局文件中引用,作为View的背景: ```xml android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/your_shape"/> `...
ViewGroup parentView = (ViewGroup) findViewById(R.id.parent_layout); for (int i = 0; i < parentView.getChildCount(); i++) { View childView = parentView.getChildAt(i); childView.setOnClickListener...