2014-01-27 4 views
0

В моем приложении есть одна кнопка на нажатие этой кнопки я показываю настраиваемое диалоговое окноКак добавить кнопку переключения в строке заголовка диалогового окна пользовательского

создать диалог, как это:

tempDialog = new Dialog(ConfigureActivity.this); 
    tempDialog.setContentView(R.layout.tempreturedialog); 
    tempDialog.setTitle("Change Temperature"); 

и расположение диалога является:

<TableLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="40dp" > 

    <TableRow 
     android:id="@+id/tableRow1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" > 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:orientation="horizontal" 
      android:weightSum="5" > 

      <EditText 
       android:id="@+id/roomTemp" 
       android:layout_width="150dp" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="10dp" 
       android:ems="10" 
       android:inputType="numberDecimal" /> 

      <Spinner 
       android:id="@+id/unit" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:entries="@array/time" 
       android:prompt="@string/Select" /> 
     </LinearLayout> 
    </TableRow> 

    <TableRow 
     android:id="@+id/tableRow9" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     > 
    </TableRow> 

    <TableRow 
     android:id="@+id/tableRow2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:layout_marginBottom="10dp"> 

     <LinearLayout android:orientation="horizontal" > 

      <TextView 
       android:id="@+id/min" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:text="Min : 0" 
       android:textAppearance="?android:attr/textAppearanceMedium" /> 

      <TextView 
       android:id="@+id/max" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:text="Max : 100" 
       android:textAppearance="?android:attr/textAppearanceMedium" /> 
     </LinearLayout> 
    </TableRow> 

    <TableRow 
     android:id="@+id/tableRow4" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="10dp" 
     android:layout_weight="1" 
     android:gravity="center" 
     android:weightSum="3" > 

     <TextView 
      android:id="@+id/textView1" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="@string/Repeat" 
      android:textAppearance="?android:attr/textAppearanceMedium" /> 

     <Spinner 
      android:id="@+id/repeatafter" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="2" 
      android:entries="@array/repeat" 
      android:prompt="@string/RepeatAfter" /> 
    </TableRow> 

    <TableRow 
     android:id="@+id/tableRow3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:gravity="center" > 

     <Button 
      android:id="@+id/setBtn" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="center" 
      android:text="Set" /> 
    </TableRow> 
</TableLayout> 

Я хочу, чтобы добавить кнопку-переключатель рядом с заголовком диалога, так что если кнопка-переключатель установлен в положение «ON» показывают некоторые содержатся в диалоговом окне, и если «OFF» какой-то другой содержит

Как я могу это сделать ??

+0

Уточните, что вы подразумеваете под названием «около названия диалога». Где именно вы пытаетесь это получить? Поскольку вы можете просто добавить эту кнопку переключения в верхнюю часть вашего макета и получить «близко» к названию диалогового окна. – dominicoder

+0

Я хочу переключить кнопку на правой стороне заголовка, как у нас, на экране настройки wifi – NewBuddy

ответ

0

Здесь,

LayoutInflater inflater = getLayoutInflater(); 

    tempDialog = new Dialog(ConfigureActivity.this); 
    tempDialog.setContentView(inflater.inflate(R.layout.tempreturedialog, null)); 
    tempDialog.setTitle("Change Temperature"); 
+0

Предоставление ошибки tempDialog.setContentView (inflater.inflate (R.layout.tempreturedialog)); Метод inflate (int, ViewGroup) в типе LayoutInflater не применимо для аргументов (int) – NewBuddy

+0

Проверьте изменение. Для этого требуется группа родительского представления, передать ее null – Hardik4560

+0

Без изменений в диалоге – NewBuddy

0

В макете добавить строку в верхней части с кнопкой TextView и тумблера. Затем не устанавливайте заголовок в диалоговом окне, а вместо этого устанавливайте его в текстовом режиме, оставляя это верхнее пространство пустым. Вы будете имитировать заголовок с помощью кнопки переключения рядом с ним.

Смежные вопросы