Как программно настраивать внешний вид виджета?

Имею виджет:


Разметка:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="center"
    android:layout_margin="2dip"
    android:background="@drawable/widget"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="3dip"
        android:layout_marginRight="3dip"
        android:layout_marginTop="3dip"
        tools:ignore="UseCompoundDrawables" >

        <TextView
            android:id="@+id/widget_title"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/app_name"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <ImageView
            android:id="@+id/edit_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="1dip"
            android:contentDescription="@string/edit"
            android:src="@drawable/widget_edit" />
    </LinearLayout>

    <TextView
        android:id="@+id/widget_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginLeft="4dip"
        android:layout_marginRight="4dip" />

</LinearLayout>



и @drawable/widget:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <stroke
        android:width="1dp"
        android:color="#FFFFFFFF" />

    <solid android:color="#00000000"/>

    <corners
        android:bottomLeftRadius="7dp"
        android:bottomRightRadius="7dp"
        android:topLeftRadius="7dp"
        android:topRightRadius="7dp" />

</shape>



Необходима возможность устанавливать цвет фона виджета, прозрачность виджета, цвет рамки и цвет/размер шрифта для обоих TextView в конфигураторе виджета. Вопрос в том, как мне получить объект TextView на виджете и как получить доступ к свойствам указанным в shape?
  • Вопрос задан
  • 6612 просмотров
Решения вопроса 1
Bublik
@Bublik
Web & Mobile developer, Head of Mobile department
Доступ к widget_title:
findviewbyid(R.id.widget_title)

Доступ к widget_content:
findviewbyid(R.id.widget_content)

Доступ к shape:
getResources().getDrawable(R.drawable.widget);
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы