天天看點

AlertDialog 源碼布局調整

AlertDialog 統一修改 布局樣式。首先要找到底層布局檔案,\frameworks\base\core\res\res\layout  下 alert_dialog_material.xml  
           
<LinearLayout
   .......
                <TextView
                    android:id="@+id/message"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:paddingEnd="?attr/dialogPreferredPadding"
                    android:paddingStart="?attr/dialogPreferredPadding"
                    android:fontFamily="@string/font_family_subhead_material"
                    android:textColor="?attr/textColorPrimary"
                    android:textSize="30dp"
                    />

             .......
    <include layout="@layout/alert_dialog_button_bar_material" />
</LinearLayout>
           

修改alert_dialog_button_bar_material

<?xml version="1.0" encoding="utf-8"?>
<!--
     Copyright (C) 2014 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<com.android.internal.widget.ButtonBarLayout
   ......

    <Button
        android:id="@+id/button3"
        style="?attr/buttonBarNeutralButtonStyle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <Space
        android:id="@+id/spacer"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_weight="0"
        android:visibility="gone" />

    <Button
        android:id="@+id/button2"
       android:layout_weight="1"
        android:layout_width="0dp"
        android:textSize="30dp"
        android:layout_height="wrap_content" />

    <Button
        android:id="@+id/button1"
        android:layout_weight="1"
        android:layout_width="0dp"
         android:textSize="30dp"
        android:layout_height="wrap_content" />
</com.android.internal.widget.ButtonBarLayout>

           

調整後布局如圖

AlertDialog 源碼布局調整