2013-07-14 134 views
3

enter image description here使用自定义主题

删除警报对话框边界在我的应用我使用与圆角矩形的警告对话框theme.But它有alertdialog矩形和我theme.My问题是如何取代像dialog.I警告对话框边界只想用自己的主题来显示这个设置项目。

我想输出这种方式,取代上述主题:

enter image description here

主要活动:

AlertDialog.Builder alertSeverity = new AlertDialog.Builder(
      getActivity(), R.style.Theme_CustomDialog); 
    alertSeverity.setTitle("Severity Status"); 
CharSequence[] severityStatus = { "Low-Severity", 
      "Middle-Severity", "High-Severity" }; 
    alertSeverity.setItems(severityStatus, 
      new DialogInterface.OnClickListener() {   

       @Override 
       public void onClick(DialogInterface dialog, int which) { 
       } 
       }); 

我的主题:

<style name="Theme.CustomDialog" parent="android:style/Theme.Dialog"> 
    <item name="android:windowBackground">@drawable/shapedialogtheme</item> 
<item name="android:windowFrame">@null</item> 

</style> 

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" > 

<solid android:color="#565656" /> 

<stroke 
    android:width="5dp" 
    android:color="#ffff8080" /> 

<corners android:radius="30dp" /> 

<padding 
    android:bottom="10dp" 
    android:left="10dp" 
    android:right="10dp" 
    android:top="10dp" /> 
<size 
    android:width="150dp" 
    android:height="150dp"/> 

</shape> 

enter image description here

+0

ü可以很容易地使通过定制而不是使用主题。 – TheFlash

+0

如何使海关 – Satheesh

+0

等待我要去邮编。 – TheFlash

回答

2

尝试下一个解决方案:

从对话框延伸,并设置使用的setContentView使用完全视图。

alertDialog用于某些功能。这并不是说它可以做任何你想做的事。

也许不是扩展你可以把对话框,然后使用setContentView。

7

使用对话框而不是AlertDialog。

创建您想要在对话框中显示的自定义布局,并在对话框中设置setContent。 在对话框中应用这个主题android.R.style.Theme_Translucent_NoTitleBar它会隐藏边框。

以下是示例代码。

Dialog dialog = new Dialog(activity.this, android.R.style.Theme_Translucent_NoTitleBar); 

// your layout file 
dialog.setContentView(R.layout.dialog); 

// for hide title 
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 

//for set title 
dialog.setTitle("Custom Dialog"); 


dialog.show(); 

更新时间:

在AlertDialog只是尝试这样做。

AlertDialog.Builder alertSeverity = new AlertDialog.Builder(
      getActivity(), android.R.style.Theme_Translucent_NoTitleBar); 
+0

嘿我想动态设置项目,所以我绝对使用alertdialog而不是对话框.. – Satheesh

+0

@Satheesh检查我更新的答案,如果它不会工作,那么你必须使用对话框..你也可以采取listview布局.. –

+0

http: //stackoverflow.com/a/5910772/624069 –

2

使用对话,而不是AlertDialog

Dialog callAlert = new Dialog(LoginActivity.this,R.style.CutomDialog); 
callAlert.setContentView(R.layout.call); 

Style.xml

<style name="CutomDialog" parent="android:style/Theme.Dialog"> 
    <item name="android:windowBackground">@android:color/transparent</item> 
    <item name="android:windowNoTitle">true</item> 
    <item name="android:windowAnimationStyle">@style/Animations.DialogAnimation</item> 
</style> 

call.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:orientation="vertical" 
android:layout_margin="20dp" 
android:background="@drawable/call_bg"></RelativeLayout> 

call_bg.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android" > 
<stroke android:width="3dp" android:color="#A20B3F" /> 

<corners android:bottomRightRadius="4dp" android:bottomLeftRadius="4dp" 
android:topLeftRadius="4dp" android:topRightRadius="4dp"/> 

主要的事情是,你必须做出布局backgrpund否则透明您将无法为你想输出。

2

你需要设计用于此目的的自定义对话框:

**dialog.xml** 

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" > 

<TextView 
    android:id="@+id/txt_view_SaveAs" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/save_as" 
    android:layout_margin="10dp" 
    android:textSize="25dp" /> 

<EditText 
    android:id="@+id/edit_txt_SaveAs" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:minWidth="300dp" 
    android:maxLines="1" 
    android:textSize="20dp" 
    android:maxLength="50" 
    android:layout_margin="10dp" 
    android:text="@string/save_as" /> 

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:layout_margin="10dp" 
    android:weightSum="1.0" > 

    <Button 
     android:id="@+id/btn_SaveAs" 
     android:layout_width="0dp" 
     android:layout_height="50dp" 
     android:layout_weight="0.5" 
     android:minWidth="100dp" 
     android:textSize="20dp" 
     android:text="@string/save" 
     android:layout_margin="3dp" /> 

    <Button 
     android:id="@+id/btn_Cancel" 
     android:layout_width="0dp" 
     android:layout_height="50dp" 
     android:layout_weight="0.5" 
     android:minWidth="100dp" 
     android:textSize="20dp" 
     android:text="@string/cancel" 
     android:layout_margin="3dp" /> 

</LinearLayout> 

然后,您可以让不同类的特定对话是这样的:

public class SaveDialog extends Dialog implements android.view.View.OnClickListener { 

private Context context; 

private TextView txt_view_SaveAs; 
private EditText edit_txt_SaveAs; 
private Button btn_SaveAs; 
private Button btn_Cancel; 

public SaveDialog(Context context) { 
    super(context); 
    this.context = context; 
    // TODO Auto-generated constructor stub 
} 

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.dialog); 

    setCancelable(true); // Setting the Dialog to be Cancellable on Back Key Press 

    txt_view_SaveAs = (TextView) findViewById(R.id.txt_view_SaveAs); 
    edit_txt_SaveAs = (EditText) findViewById(R.id.edit_txt_SaveAs); 
    btn_SaveAs = (Button) findViewById(R.id.btn_SaveAs); 
    btn_SaveAs.setOnClickListener(this); 
    btn_Cancel = (Button) findViewById(R.id.btn_Cancel); 
    btn_Cancel.setOnClickListener(this); 
} 

@Override 
public void onClick(View v) { 
     // Write code for all the buttons on click methods 
} 
} 

然后就可以调用您的主类中的自定义对话框通过使用以下代码:

SaveDialog save_dialog = new SaveDialog(saving_activity); 
save_dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
save_dialog.show(); 
2

您无法从警报对话框中删除边框。

使用本

public class ActivityIndicator extends Dialog implements android.view.View.OnClickListener{ 
protected static final String TAG = InfoIndicator.class.getName(); 
ImageView close; 
WebView info; 

     public ActivityIndicator (Context context,String information) 
     { 
      super(context, android.R.style.Theme_Translucent_NoTitleBar); 
      requestWindowFeature(Window.FEATURE_NO_TITLE); 
      setContentView(R.layout.info); 
      setCancelable(true); 
      } 
} 

,并尝试这下面的播放功能,隐藏和清晰的对话

private static ActivityIndicator activityIndicator; 

public static void hideActivityViewer() { 
    if (activityIndicator != null) { 
     activityIndicator.dismiss(); 
    } 
    activityIndicator = null; 
} 

public static void showActivityViewer(Context context) { 
    if (activityIndicator == null) 
    { 
     activityIndicator = new ActivityIndicator(context); 
    } 
    activityIndicator.show(); 

} 
public static void clearDialogs() 
{ 
    activityIndicator = null; 
} 
+0

Hai我想只显示我的custome主题而没有alertdialog边框 – Satheesh

+0

是否有任何可能的删除警报对话框边框,并设置我自己的主题... – Satheesh

+0

不,你不能删除警告对话框边框 –

1

你可以自己使用popwindow更多风格