2016-04-01 7 views
1

私は現在、AlertDialogを使用してユーザにプロンプ​​トを表示し、評価を求めています。これは、ASエミュレータ(Nexus 5 API 23)を使用したときの動作を正確に示しています。エミュレータからAlertDialogボタンのテキスト書式設定が一部のデバイスで完全に間違っています

enter image description here

しかし、私は、私の友人のデバイス上でダイアログをテストしたLGスタイロ(アンドロイド5.1.1は、API 22)と書式設定が完全​​に間違っています。ボタンの順序が間違っていて、正しくフォーマットされていません。 LGスタイロから

enter image description here

私はフォーマットがAlertDialogのために正しいことを保証することについては移動する方法がわからないと私は正直にフォーマットがLGに正しくない理由はわかりませんStylo、そして残念ながら私は現在それをテストするための別のデバイスを持っていません。

ありがとうございます!

+0

エミュレータでAPI 22、つまり5.1.1でテストしましたか? –

+0

'android.app.AlertDialog'または' android.support.v7.app.AlertDialog'を使用していますか? –

+0

スタイルを設定しないと、デバイステーマを設定してもデバイスが独自のデフォルトスタイルを使用することがあります。あなたがスタイルを設定していない場合は、そのようなものです。 –

答えて

3

既存のスタイルを親として使用してスタイルを作成し、次にそれをAlertDialog.Builder()メソッドで使用する必要があります。

それは次のようになります。

<style name="myAlertStyle" parent="AlertDialog.Material"> 
    <item name="fullDark">@empty</item> 
    <item name="topDark">@empty</item> 
    <item name="centerDark">@empty</item> 
    <item name="bottomDark">@empty</item> 
    <item name="fullBright">@empty</item> 
    <item name="topBright">@empty</item> 
    <item name="centerBright">@empty</item> 
    <item name="bottomBright">@empty</item> 
    <item name="bottomMedium">@empty</item> 
    <item name="centerMedium">@empty</item> 
    <item name="layout">@layout/alert_dialog_material</item> 
    <item name="listLayout">@layout/select_dialog_material</item> 
    <item name="progressLayout">@layout/progress_dialog_material</item> 
    <item name="horizontalProgressLayout">@layout/alert_dialog_progress_material</item> 
    <item name="listItemLayout">@layout/select_dialog_item_material</item> 
    <item name="multiChoiceItemLayout">@layout/select_dialog_multichoice_material</item> 
    <item name="singleChoiceItemLayout">@layout/select_dialog_singlechoice_material</item> 
</style> 

、その後、あなただけ(AlertDialog.Builderを使用します)このように:

AlertDialog.Builder(mContext, R.style.myAlertStyle); 
+0

あなたのマシン上のsdkを常に見て、すべてのデフォルトスタイルがどのように作成されているかを確認することができます。それは私がこのサンプルを入手したところです:)彼らは 'pathToYourSdk/sdk/platforms/android - ##/data/res/values /'に住んでいます。 –

1

それは、これはかなり多くのバグであることは注目に値しますapi-22サポートライブラリは、すべてのボタンを1つの行に配置しようとしているためです。 api-23サポートライブラリでは、各ボタンがそれ自身の行にある新しいレイアウトに切り替えることで修正されています。

私は、サポートライブラリAlertDialogとKitKat 4.4.4を搭載したデバイスで、2つの異なるプロジェクトでコードをテストしました。

両方の試験について同じコード:

import android.support.v7.app.AlertDialog; 
import android.support.v7.app.AppCompatActivity; 

public class MainActivity extends AppCompatActivity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     Toolbar toolbar = (Toolbar) findViewById(R.id.tool_bar); 
     setSupportActionBar(toolbar); 

     AlertDialog.Builder builder = new AlertDialog.Builder(this); 
     builder.setMessage("If you like this app, please rate it on the Google Play Store!") 
       .setPositiveButton("Rate me!", new DialogInterface.OnClickListener() { 
        @Override 
        public void onClick(DialogInterface dialog, int which) { 

        } 
       }) 
       .setNegativeButton("No thanks and do not ask me again", new DialogInterface.OnClickListener() { 
        @Override 
        public void onClick(DialogInterface dialog, int which) { 

        } 
       }) 
       .setNeutralButton("Remind me later", new DialogInterface.OnClickListener() { 
        @Override 
        public void onClick(DialogInterface dialog, int which) { 

        } 
       }); 
     builder.create().show(); 
    } 
} 

まず、プロジェクトにこのGradleの構成を有する(すべてのAPI-22の設定は):

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 22 
    buildToolsVersion "21.1.2" 

    defaultConfig { 
     applicationId "com.example.myapplication" 
     minSdkVersion 15 
     targetSdkVersion 22 
     versionCode 1 
     versionName "1.0" 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    compile 'com.android.support:appcompat-v7:22.2.1' 
} 

これは結果であります

enter image description here

次に、このコンフィグレーションを持つ別のプロジェクトイオン(すべてのAPI-23の設定):

enter image description here

ので、これのための1つの修正プログラムは、API-23のサポートライブラリを使用するために、次のようになります。これは、同じコードの結果です

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 23 
    buildToolsVersion "21.1.2" 

    defaultConfig { 
     applicationId "com.example.testprojecttwo" 
     minSdkVersion 15 
     targetSdkVersion 23 
     versionCode 1 
     versionName "1.0" 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    compile 'com.android.support:appcompat-v7:23.1.1' 
    compile 'com.android.support:design:23.1.1' 
} 

関連する問題