1
我一直在設計一個對話框來評價我的遊戲。我設計了看起來像這樣一個XML文件 -在對話框中不顯示Android平面按鈕
<?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>
但是當使用它作爲對話的扁平按鈕莫名其妙地轉換爲普通按鈕像這個 -
用於顯示它的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();
}
}
我做錯了什麼?
爲什麼你不想只創建一個帶有正面,負面和中性按鈕的簡單警報對話框? –
應用程序評估者類是隨處可用的,我只是想設計自己的可配置xml,雖然我不太瞭解警報對話框 –
我的意思是你有你的AppRater函數showRateDialog。在這個函數中你可以創建自定義對話框,但是你可以使用AlertDialog,它已經被設計了。如果你想,我可以張貼我的答案與代碼示例 –