2016-07-18 6 views
1

ゲームを評価するためのダイアログをデザインしようとしています。私はこのようなXMLファイルに設計されています -Androidフラットボタンがダイアログに表示されない

Rate App XML Design

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:background="#F5F5F5"> 

<LinearLayout 
    android:id="@+id/LL1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginBottom="8dp" 
    android:layout_marginLeft="24dp" 
    android:layout_marginRight="24dp" 
    android:layout_marginTop="24dp"> 

    <ImageView 
     android:id="@+id/image" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginRight="10dp" /> 

    <TextView 
     android:id="@+id/text" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 

     android:layout_marginTop="10dp" 
     android:text="Rate My game" 
     android:textColor="#000000" 
     android:textSize="24sp" /> 

</LinearLayout> 

<View 
    android:id="@+id/singleLine" 
    android:layout_width="fill_parent" 
    android:layout_height="2dp" 
    android:layout_below="@id/LL1" 
    android:layout_marginBottom="8dp" 
    android:background="#2196F3" /> 


<TextView 
    android:id="@+id/Description_text" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/singleLine" 
    android:layout_marginBottom="24dp" 
    android:layout_marginLeft="24dp" 
    android:layout_marginRight="24dp" 
    android:layout_marginTop="12dp" 
    android:text="If you enjoy Playing My Game take a moment to rate 
    it. Thanks for your Support!" 
    android:textColor="#000000" 
    android:textSize="16sp" /> 


<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/Description_text" 

    android:layout_margin="8dp"> 

    <Button 
     android:id="@+id/rate_button" 
     style="?android:attr/borderlessButtonStyle" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="2" 
     android:text="RATE" 
     android:textAllCaps="true" 
     android:textColor="#424242" 
     android:textSize="14sp" 

     /> 

    <Button 
     android:id="@+id/remind_me_later_button" 
     style="?android:attr/borderlessButtonStyle" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 

     android:layout_weight="4" 
     android:text="REMIND ME LATER" 
     android:textAllCaps="true" 
     android:textColor="#424242" 
     android:textSize="14sp" 

     /> 

    <Button 
     android:id="@+id/never_button" 
     style="?android:attr/borderlessButtonStyle" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 

     android:layout_weight="2" 
     android:text="NEVER" 
     android:textAllCaps="true" 
     android:textColor="#424242" 
     android:textSize="14sp" 

     /> 


</LinearLayout> 

をしかし、ダイアログとしてそれを使用する場合は、フラットボタンは何とかthis-

Flat button in XML

のような通常のボタンに変換し、

表示するJavaコード -

public class AppRater extends AppCompatActivity { 
private final static String APP_TITLE = "My Game"; 
private final static String APP_PNAME = "com.alala.blabla"; 

private final static int DAYS_UNTIL_PROMPT = 0; 
private final static int LAUNCHES_UNTIL_PROMPT = 1; 

public static void app_launched(Context mContext) { 
    SharedPreferences prefs = mContext.getSharedPreferences("apprater", 0); 
    if (prefs.getBoolean("dontshowagain", false)) { 
     return; 
    } 

    SharedPreferences.Editor editor = prefs.edit(); 

    // Increment launch counter 
    long launch_count = prefs.getLong("launch_count", 0) + 1; 
    editor.putLong("launch_count", launch_count); 

    // Get date of first launch 
    Long date_firstLaunch = prefs.getLong("date_firstlaunch", 0); 
    if (date_firstLaunch == 0) { 
     date_firstLaunch = System.currentTimeMillis(); 
     editor.putLong("date_firstlaunch", date_firstLaunch); 
    } 

    // Wait at least n days before opening 
    if (launch_count >= LAUNCHES_UNTIL_PROMPT) { 
     if (System.currentTimeMillis() >= date_firstLaunch + 
       (DAYS_UNTIL_PROMPT * 24 * 60 * 60 * 1000)) { 
      showRateDialog(mContext, editor); 
     } 
    } 

    editor.commit(); 
} 

public static void showRateDialog(final Context mContext, 
final SharedPreferences.Editor editor) { 


    final Dialog dialog = new Dialog(mContext, R.style.FullHeightDialog); 
    dialog.setContentView(R.layout.customapprater); 
    Button b1 = (Button) dialog.findViewById(R.id.rate_button); 
    b1.setOnClickListener(new OnClickListener() { 
     public void onClick(View v) { 
      if (editor != null) { 
       editor.putBoolean("dontshowagain", true); 
       editor.commit(); 
      } 
      mContext.startActivity(new Intent(
Intent.ACTION_VIEW,  Uri.parse("market://details?id=" + APP_PNAME))); 
      dialog.dismiss(); 
     } 
    }); 


    Button b2 = (Button) dialog.findViewById(R.id.remind_me_later_button); 
    b2.setOnClickListener(new OnClickListener() { 
     public void onClick(View v) { 
      if (editor != null) { 
       editor.clear().commit(); 
      } 
      dialog.dismiss(); 
     } 
    }); 


    Button b3 = (Button) dialog.findViewById(R.id.never_button); 

    b3.setOnClickListener(new OnClickListener() { 
     public void onClick(View v) { 
      if (editor != null) { 
       editor.putBoolean("dontshowagain", true); 
       editor.commit(); 
      } 
      dialog.dismiss(); 
     } 
    }); 
    dialog.show(); 
} 
} 

私は間違っていますか?

+0

肯定的、否定的、ニュートラルなボタンで簡単な警告ダイアログを作成したくないのはなぜですか? –

+0

アプリレータークラスはどこでも利用できます。私は自分の設定可能なxmlをデザインしたいと思っていますが、警告ダイアログについてはあまり知られていません。 –

+0

あなたはAppRater関数 'showRateDialog'を持っています。この関数では、カスタムダイアログを作成しますが、AlertDialogを使用することができます.AlertDialogは既にスタイリングされています。あなたが望むなら、私はコード –

答えて

0

ダイアログをAlertDialogに変更してください。あなたはそれらについてhereを読むことができます。

public static void showRateDialog(final Context mContext, final SharedPreferences.Editor editor) { 
    new AlertDialog.Builder(mContext) 
      .setTitle(R.string.rate_dialog_title) 
      .setMessage(R.string.rate_dialog_message) 
      .setPositiveButton(R.string.rate, new DialogInterface.OnClickListener() { 
       @Override 
       public void onClick(DialogInterface dialog, int which) { 
        if (editor != null) { 
         editor.putBoolean("dontshowagain", true); 
         editor.commit(); 
        } 

        mContext.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + APP_PNAME))); 
       } 
      }) 
      .setNegativeButton(R.string.never, new DialogInterface.OnClickListener() { 
       @Override 
       public void onClick(DialogInterface dialog, int which) { 
        if (editor != null) { 
         editor.putBoolean("dontshowagain", true); 
         editor.commit(); 
        } 
       } 
      }) 
      .setNeutralButton(R.string.remind_later, new DialogInterface.OnClickListener() { 
       @Override 
       public void onClick(DialogInterface dialog, int which) { 
        if (editor != null) { 
         editor.clear().commit(); 
        } 
       } 
      }) 
      .show(); 
} 

さらに詳しい情報AlertDialog.Builder

+0

。今私はXMLをinflateを使って追加することができます:) –

関連する問題