2015-08-16 3 views
0

Я не могу изменить белый фон кнопок. Я хочу прозрачный фон, соответствующий верхнему прозрачному фону. Я попробовал несколько методов, но не работал. Есть ли способ сделать это?Прозрачный опознавательный знак кнопки фона

enter image description here

public void onNextClick() { 
     LayoutInflater layoutInflater = LayoutInflater.from(AuthenticatorActivity.this); 
     View promptView = layoutInflater.inflate(R.layout.input_user_info, null); 
     AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(AuthenticatorActivity.this); 
     alertDialogBuilder.setView(promptView); 

     // setup a dialog window 
     alertDialogBuilder.setCancelable(false).setPositiveButton("Submit", new DialogInterface.OnClickListener() { 
      public void onClick(DialogInterface dialog, int id) { 

      } 
     }) 

     .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { 
      public void onClick(DialogInterface dialog, int id) { 
       dialog.cancel(); 
      } 
     }); 

     // create an alert dialog 
     AlertDialog alert = alertDialogBuilder.create(); 
     alert.getWindow().setBackgroundDrawableResource(android.R.color.transparent); 
     alert.show(); 
     alert.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.argb(0, 200, 200, 200))); 
     alert.getWindow().setLayout(450, 450); 


     Button btnSubmit = alert.getButton(DialogInterface.BUTTON_POSITIVE); 
     btnSubmit.setBackgroundColor(Color.TRANSPARENT); 

     Button btnCancel = alert.getButton(DialogInterface.BUTTON_NEGATIVE); 
     btnCancel.setBackgroundColor(Color.TRANSPARENT); 
    } 

ответ

0

попробовать положить #00010000 на кнопки 'фоне' недвижимости в R.layout.input_user_info

+0

Кнопки не находятся в xml. Они генерируются из кода. – Rashed

+0

@Rashed после тестирования вашего кода. он работает на моем телефоне, кнопки прозрачные – derfect

+0

Где вы разместили код цвета? В input_user_info нет свойства фона кнопки. – Rashed

0

Добавить пользовательскую кнопку макета в R.layout.input_user_info, и сделать его прозрачным, как это:

<RelativeLayout 
    android:id="@+id/parent" 
    android:layout_width="match_parent" 
    android:layout_height="150" 
    android:background="@drawable/abackground"> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:layout_marginTop="10dp" 
     android:layout_alignParentBottom="true"> 
     <Button 
      android:id="@+id/b_cancel" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1.0" 
      android:text="Cancel" 
      style="@style/Widget.AppCompat.Button.Borderless"/> 
     <View 
      android:layout_width="1dp" 
      android:layout_height="match_parent" 
      android:background="#c8000000"/> 
     <Button 
      android:id="@+id/b_submit" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1.0" 
      android:text="Submit" 
      style="@style/Widget.AppCompat.Button.Borderless"/> 
    </LinearLayout> 
</RelativeLayout> 

При событии click:

View promptView = layoutInflater.inflate(R.layout.input_user_info, null); 
cancel_button = (Button)promptView.findViewById(R.id.b_cancel); 
submit_button = (Button)promptView.findViewById(R.id.b_submit); 
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(AuthenticatorActivity.this); 
alertDialogBuilder.setView(promptView); 
final AlertDialog alert = alertDialogBuilder.create(); 
cancel_button.setOnClickListener(new View.OnClickListener(){ 
     @Override 
     public void onClick(View v) { 
      alert.cancel; 
     } 
    }); 
submit_button.setOnClickListener(new View.OnClickListener(){ 
     @Override 
     public void onClick(View v) { 
      //Do some thing 

     } 
    }); 

Layout понравится: Layout will like this

+0

xml код в порядке, но alertdialog не поддерживает вышеуказанный Java-код. – Rashed

0

вы можете использовать это вместо

XML:

android:background="@android:color/transparent" 

Via Коды:

bSubmit.setBackgroundResource(android.R.color.transparent); 

ИЛИ вы можете создать вытяжке для менеджера клик состояний:

<item android:state_pressed="true" > 
    <shape android:shape="rectangle" > 

     <solid 
      android:color="#757575" /> 
     <padding 
      android:left="10dp" 
      android:right="10dp"/> 

    </shape> 
</item> 

<item> 
    <shape android:shape="rectangle" > 

     <solid 
      android:color="@android:color/transparent" /> 
     <padding 
      android:left="10dp" 
      android:right="10dp"/> 

    </shape> 
</item> 

надеюсь, что это помогает. счастливые кодировки.

0

Просто используйте TextView с android:background="@null". Если вам нужны линии между TextViews, вы можете добавить еще один вид в свой макет.

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