I would set the background of the widget to a stateful drawable such
as is the case with most of the built-in Android widgets. For example
here's the background for a default button:
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2008 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
See the License for the specific language governing permissions
and
limitations under the License.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false"
android:state_enabled="true"
android:drawable="@drawable/btn_default_normal" />
<item android:state_window_focused="false"
android:state_enabled="false"
android:drawable="@drawable/btn_default_normal_disable" />
<item android:state_pressed="true"
android:drawable="@drawable/btn_default_pressed" />
<item android:state_focused="true" android:state_enabled="true"
android:drawable="@drawable/btn_default_selected" />
<item android:state_enabled="true"
android:drawable="@drawable/btn_default_normal" />
<item android:state_focused="true"
android:drawable="@drawable/
btn_default_normal_disable_focused" />
<item
android:drawable="@drawable/btn_default_normal_disable" />
</selector>
On Oct 21, 1:23 pm, Mark Wyszomierski <[email protected]> wrote:
> Hi,
>
> I made a custom widget (which is just a composite like):
>
> <LinearLayout>
> <TextView>
> </LinearLayout>
>
> this widget is focusable and reacts to touches. I'd like it to change
> its background color to the default system highlight color when the
> user scrolls to it, and have it blink when the user taps it (just like
> an element of a ListView does).
>
> I can add an OnFocusChangeListener for when the user scrolls to it,
> and in the handler do the changing of the background color.
>
> How would I add the 'blinking' behavior though when the user just taps
> it with a finger? I did something like this as a test:
>
> setOnTouchListener(new OnTouchListener() {
> public boolean onTouch(View v, MotionEvent event) {
> // Requesting focus triggers my OnFocusChangeListener which
> changes the bg color.
> requestFocusFromTouch();
> new Handler().postDelayed(new Runnable() {
> public void run() {
> clearFocus();
> }
> }, 300);
> return false;
> }
> });
>
> this is just a guess. Is there a correct way of implementing this
> behavior?
>
> Thanks
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---