【问题标题】:Custom theme of all dialogs in an app应用程序中所有对话框的自定义主题
【发布时间】:2013-02-01 15:37:04
【问题描述】:

是否有类似HoloColorsAction Bar Style Generator 的主题生成器可以帮助我们更改应用中的Dialogs 和AlertDialogs 的主题?

我的应用程序使用 Holo 主题,并且我设法更改了视图的样式,例如 EditTexts 和 Buttons,但是当它们出现在对话框中时它们保持不变。我还想更改标题下蓝线的颜色。

我发现了一些与此主题相关的问题和答案,但他们实际上说这甚至是不可能的。我不敢相信它不是。

【问题讨论】:

    标签: android styles android-dialog android-theme


    【解决方案1】:

    至少对于 AlertDialog 是可能的。在这里,我发布了一个函数的解决方案,该函数在您的代码中的某个时间点(例如按钮单击)被调用,并在您的屏幕上创建一个警报对话框自己的布局。布局是一个普通的 layout.xml,您可以定义您的方式想。非常适合我!

    private void showAddUserGeneratedStationDialog() {
    
            AlertDialog.Builder alertDialog = new AlertDialog.Builder(
                    AmplifyActivity.this);
    
            LayoutInflater inflater = getLayoutInflater();
    
                //inflate your layout.xml
            alertDialog
                    .setView(inflater.inflate(R.layout.dialog_add_station, null));
    
                //show dialog over activity screen
            final AlertDialog ad = alertDialog.show();
    
                //put actions to your ui-elements
            Button cancelBtn = (Button) ad
                    .findViewById(R.id.list_user_generated_cancelBU);
            cancelBtn.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    ad.cancel();
                }
            });
    
            Button doneBtn = (Button) ad
                    .findViewById(R.id.list_user_generated_doneBU);
            doneBtn.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                                //get sth from your layout f.e. some textInput
                    String stationUrl = ((TextView) ad
                            .findViewById(R.id.list_user_generated_stationURLInput))
                            .getText().toString();
    
                        // did some other things
    
                    ad.dismiss();
    
                }
            });
    
        }
    

    还有我的 layout.xml

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/list_user_generated_addStationDialog"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#99000000"
        android:clickable="true"
        android:gravity="center"
        android:orientation="vertical" >
    
        <LinearLayout
            android:layout_width="300dp"
            android:layout_height="200dp"
            android:padding="10dp"
            android:background="#000"
            android:orientation="vertical" >
    
            <LinearLayout
                xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:tools="http://schemas.android.com/tools"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal" >
    
                <Button
                    android:id="@+id/list_user_generated_cancelBU"
                    style="@style/ButtonStyle"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center|right"
                    android:text="@string/cancel" />
    
                <TextView
                    style="@style/AmplifyHeadlineElement"
                    android:layout_width="0dp"
                    android:layout_height="fill_parent"
                    android:layout_weight="1"
                    android:text="@string/list_userGenerated_addStation" />
    
                <Button
                    android:id="@+id/list_user_generated_doneBU"
                    style="@style/ButtonStyle"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center|right"
                    android:text="@string/done" />
            </LinearLayout>
    
            <EditText
                android:id="@+id/list_user_generated_stationURLInput"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="20dp"
                android:layout_marginTop="10dp"
                android:background="#FFF"
                android:ems="10"
                android:hint="@string/list_userGenerated_addUrlExample"
                android:inputType="textNoSuggestions" >
            </EditText>
    
            <!-- MORE BUT I DELETED  IT FOR BETTER OVERVIEW -->
        </LinearLayout>
    </LinearLayout>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多