Здравствуйте!
Помогите начинающему девелоперу
Пишу будильник (интерфейс "копирую" со стандартного).
В настройках будильника внутри LinearLayout вставил по 2 TextView (описание и значение).
Событие onClick обрабатываю от Layout-а.
Как сделать так, чтобы при нажатии на Layout он выделялся синим прямоугольником выделения (как элемент ListView) ???
Или, может есть другой (стандартный?) способ отображения этого прямоугольника?
Выделение TextView прямоугольником выделения
Выделение TextView прямоугольником выделения
- Вложения
-
- Скрин
- 1.jpg (47.1 КБ) 4473 просмотра
Re: Выделение TextView прямоугольником выделения
Ставишь на Layout background такую xml:
где normal и pressed соответствующие хмл или всемто них можно просто цвета
Код: Выделить всё
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false"
android:drawable="@drawable/normal">
</item>
<item android:state_pressed="true"
android:drawable="@drawable/pressed">
</item></selector>
Личные сообщения с просьбой ответить на форуме или написать программу я просто удаляю, если я в хорошем настроении. Если в плохом добавляю автора в черный список. По любым другим вопросам feel free to write to me.
Re: Выделение TextView прямоугольником выделения
Спасибо!anber писал(а):Ставишь на Layout background такую xml:где normal и pressed соответствующие хмл или всемто них можно просто цветаКод: Выделить всё
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="false" android:drawable="@drawable/normal"> </item> <item android:state_pressed="true" android:drawable="@drawable/pressed"> </item></selector>
А в каких ресурсах хранятся стандартные цвета и прямоугольники нажатого/отжатого состояния?
Re: Выделение TextView прямоугольником выделения
цвета - http://stackoverflow.com/a/7323234/1159507
До стандартных прямоугольников можно достучаться например для кнопки - android.R.drawable.btn_default, но они зависят от версии андроида, так что лучше их скопировать из какого-либо проекта типа HoloEverywhere: https://github.com/Prototik/HoloEverywh ... s/drawable
см. также http://stackoverflow.com/questions/1382 ... dittext-fr
До стандартных прямоугольников можно достучаться например для кнопки - android.R.drawable.btn_default, но они зависят от версии андроида, так что лучше их скопировать из какого-либо проекта типа HoloEverywhere: https://github.com/Prototik/HoloEverywh ... s/drawable
см. также http://stackoverflow.com/questions/1382 ... dittext-fr
Личные сообщения с просьбой ответить на форуме или написать программу я просто удаляю, если я в хорошем настроении. Если в плохом добавляю автора в черный список. По любым другим вопросам feel free to write to me.
Re: Выделение TextView прямоугольником выделения
Спасибо! с этим вроде разобрался.anber писал(а):цвета - http://stackoverflow.com/a/7323234/1159507
До стандартных прямоугольников можно достучаться например для кнопки - android.R.drawable.btn_default, но они зависят от версии андроида, так что лучше их скопировать из какого-либо проекта типа HoloEverywhere: https://github.com/Prototik/HoloEverywh ... s/drawable
см. также http://stackoverflow.com/questions/1382 ... dittext-fr
Еще вопрос возник. при открытии активити редактирования будильника фокус переходил на EditText. я его убрал:
Код: Выделить всё
.setSelected(false);
Вот мой активити:
[syntax=xml]<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="1dp"
android:background="@android:color/background_dark"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:gravity="top|center_horizontal"
android:orientation="vertical"
android:padding="2dp" >
<CheckBox
android:id="@+id/checkBoxEnabled"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="@string/AddEditchkEnabled"
android:textSize="20sp"
android:textStyle="bold" />
<LinearLayout
android:id="@+id/llTime"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="@layout/custom_background"
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical" >
<TextView
android:id="@+id/TextTime"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="@string/StringTime"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="@+id/tvTimeValue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="1dp"
android:layout_weight="1"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:textSize="14sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/llDaysOfWeek"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_marginBottom="1dp"
android:background="@layout/custom_background"
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical" >
<TextView
android:id="@+id/TextDaysOfWeek"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="@string/StringDaysOfWeek"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="@+id/tvDaysOfWeekValue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="1dp"
android:layout_weight="1"
android:focusable="false"
android:focusableInTouchMode="false"
android:textSize="14sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/llRintone"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="@layout/custom_background"
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical" >
<TextView
android:id="@+id/TextRingtone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="@string/StringRingtone"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="@+id/tvRingtoneValue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="1dp"
android:layout_weight="1"
android:focusable="false"
android:focusableInTouchMode="false"
android:textSize="14sp" />
</LinearLayout>
<CheckBox
android:id="@+id/checkBoxVibrate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:gravity="center_vertical"
android:text="@string/chkVibrate"
android:textSize="20sp"
android:textStyle="bold" />
<EditText
android:id="@+id/etDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:hint="@string/StringDescriptionHint"
android:textStyle="italic" >
</EditText>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp" >
<Button
android:id="@+id/btSave"
style="?android:attr/borderlessButtonStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="onClick"
android:text="@string/AddEditSave" />
<Button
android:id="@+id/btCancel"
style="?android:attr/borderlessButtonStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="onClick"
android:text="@string/AddEditCancel" />
</LinearLayout>
</LinearLayout>[/syntax]
Обработчики назначены программно
Re: Выделение TextView прямоугольником выделения
Всё, сам разобрался. Изменил XML вот так:
[syntax=xml]<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="1dp"
android:background="@android:color/background_dark"
android:clickable="false"
android:focusable="false"
android:gravity="top|center_horizontal"
android:orientation="vertical"
android:padding="2dp" >
<CheckBox
android:id="@+id/checkBoxEnabled"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="@string/AddEditchkEnabled"
android:textSize="18sp"
android:textStyle="bold" />
<LinearLayout
android:id="@+id/llTime"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="@layout/custom_background"
android:clickable="true"
android:focusable="true"
android:orientation="vertical" >
<TextView
android:id="@+id/TextTime"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:clickable="false"
android:focusable="false"
android:text="@string/StringTime"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="@+id/tvTimeValue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="1dp"
android:layout_weight="1"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/llDaysOfWeek"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_marginBottom="1dp"
android:background="@layout/custom_background"
android:clickable="true"
android:focusable="true"
android:orientation="vertical" >
<TextView
android:id="@+id/TextDaysOfWeek"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:focusable="false"
android:text="@string/StringDaysOfWeek"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="@+id/tvDaysOfWeekValue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="1dp"
android:layout_weight="1"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/llRintone"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="@layout/custom_background"
android:clickable="true"
android:focusable="true"
android:orientation="vertical" >
<TextView
android:id="@+id/TextRingtone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:focusable="false"
android:text="@string/StringRingtone"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="@+id/tvRingtoneValue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="1dp"
android:layout_weight="1"
android:focusable="false"
android:textSize="12sp" />
</LinearLayout>
<CheckBox
android:id="@+id/checkBoxVibrate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:gravity="center_vertical"
android:text="@string/chkVibrate"
android:textSize="18sp"
android:textStyle="bold" />
<EditText
android:id="@+id/etDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:hint="@string/StringDescriptionHint"
android:textStyle="italic" >
</EditText>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp" >
<Button
android:id="@+id/btSave"
style="?android:attr/borderlessButtonStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="onClick"
android:text="@string/AddEditSave" />
<Button
android:id="@+id/btCancel"
style="?android:attr/borderlessButtonStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="onClick"
android:text="@string/AddEditCancel" />
</LinearLayout>
</LinearLayout>[/syntax]
Убрал Clickable и Focusable у ненужных элементов.
[syntax=xml]<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="1dp"
android:background="@android:color/background_dark"
android:clickable="false"
android:focusable="false"
android:gravity="top|center_horizontal"
android:orientation="vertical"
android:padding="2dp" >
<CheckBox
android:id="@+id/checkBoxEnabled"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="@string/AddEditchkEnabled"
android:textSize="18sp"
android:textStyle="bold" />
<LinearLayout
android:id="@+id/llTime"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="@layout/custom_background"
android:clickable="true"
android:focusable="true"
android:orientation="vertical" >
<TextView
android:id="@+id/TextTime"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:clickable="false"
android:focusable="false"
android:text="@string/StringTime"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="@+id/tvTimeValue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="1dp"
android:layout_weight="1"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/llDaysOfWeek"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_marginBottom="1dp"
android:background="@layout/custom_background"
android:clickable="true"
android:focusable="true"
android:orientation="vertical" >
<TextView
android:id="@+id/TextDaysOfWeek"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:focusable="false"
android:text="@string/StringDaysOfWeek"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="@+id/tvDaysOfWeekValue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="1dp"
android:layout_weight="1"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/llRintone"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="@layout/custom_background"
android:clickable="true"
android:focusable="true"
android:orientation="vertical" >
<TextView
android:id="@+id/TextRingtone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:focusable="false"
android:text="@string/StringRingtone"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="@+id/tvRingtoneValue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="1dp"
android:layout_weight="1"
android:focusable="false"
android:textSize="12sp" />
</LinearLayout>
<CheckBox
android:id="@+id/checkBoxVibrate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:gravity="center_vertical"
android:text="@string/chkVibrate"
android:textSize="18sp"
android:textStyle="bold" />
<EditText
android:id="@+id/etDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:hint="@string/StringDescriptionHint"
android:textStyle="italic" >
</EditText>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp" >
<Button
android:id="@+id/btSave"
style="?android:attr/borderlessButtonStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="onClick"
android:text="@string/AddEditSave" />
<Button
android:id="@+id/btCancel"
style="?android:attr/borderlessButtonStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="onClick"
android:text="@string/AddEditCancel" />
</LinearLayout>
</LinearLayout>[/syntax]
Убрал Clickable и Focusable у ненужных элементов.