2016-07-18 2 views
1

저는 게임을 평가할 대화 상자를 디자인하려고했습니다. 나는이처럼 보이는 XML 파일 설계 한 -안드로이드 평면 단추가 대화 상자에 표시되지 않습니다.

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

처럼 일반 버튼으로 변환

자바 코드 표시에 사용 -

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를 사용할 수 있습니다. 원하는 경우 코드 샘플 –

답변

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

감사합니다. 이제 inflate를 사용하여 XML을 추가 할 수 있습니다 :) –

관련 문제