Android 修改AlertDialog原生setPositiveButton的字体颜色背景颜色大小边距位置
生活随笔
收集整理的這篇文章主要介紹了
Android 修改AlertDialog原生setPositiveButton的字体颜色背景颜色大小边距位置
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
?看效果圖:
?
public void lanyaClick(View v) {//點擊確定之后轉(zhuǎn)向登陸框LayoutInflater factory = LayoutInflater.from(Beforestart.this);//得到自定義對話框final View DialogView = factory.inflate(R.layout.item_alert_dialog, null);//創(chuàng)建對話框android.app.AlertDialog dlg = new AlertDialog.Builder(Beforestart.this).setTitle("").setView(DialogView).setPositiveButton("登錄", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int whichButton) {Button Button1 = (Button) findViewById(R.id.blechongdian);//添加按鈕點擊事件的監(jiān)聽器Button1.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {binder.setData("Loginpassword", //實現(xiàn)界面跳轉(zhuǎn)Intent intent = new Intent();intent.setClass(Beforestart.this, BluetoothCharging.class);startActivity(intent);}});}}).create();dlg.getWindow().setBackgroundDrawableResource(R.drawable.yuanjiao5); //設(shè)置對話框的樣式dlg.show();Button button = dlg.getButton(AlertDialog.BUTTON_POSITIVE);LinearLayout.LayoutParams cancelBtnPara = (LinearLayout.LayoutParams) button.getLayoutParams();//設(shè)置按鈕的大小cancelBtnPara.height = LinearLayout.LayoutParams.WRAP_CONTENT;cancelBtnPara.width = LinearLayout.LayoutParams.MATCH_PARENT;//設(shè)置文字居中cancelBtnPara.gravity = Gravity.CENTER;//設(shè)置按鈕左上右下的距離cancelBtnPara.setMargins(100, 50, 100, 30);button.setLayoutParams(cancelBtnPara);button.setBackground(ContextCompat.getDrawable(this, R.drawable.bg_yuanjiao));button.setTextColor(ContextCompat.getColor(this, R.color.white));button.setTextSize(16);}?主要的代碼是show下面的:
?
總結(jié)
以上是生活随笔為你收集整理的Android 修改AlertDialog原生setPositiveButton的字体颜色背景颜色大小边距位置的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 上海python暑假培训班
- 下一篇: android sina oauth2.