我正在使用一些复选框,它会显示在一个对话框上(动态地)。接下来我需要让对话框变得透明。我尝试了很多方法,但是失败了(浪费了整整一天)。可以请任何人给我一个解决方案
注意:目前我在对话框中显示白色(不透明) 以下是代码..... Transparent_alert.java
public class Transparent_alert extends Activity{
String tag="Transparent_alert class";
static final String KEY_USERID = "userid";
String errormsg = "", user_id;
SessionManager session;
int k=0;
Intrested_in_adapter m_adapter;
private Builder mDialog;
private Dialog alertDialog;
List<Requestencapsulation> offferList;
List<Offeringencapsulation> offerlist;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
HashMap<String, String> user = session.getUserDetails();
user_id = user.get(SessionManager.KEY_ID);
setContentView(R.layout.requests);
new Serviceclass1().execute();
}
class Serviceclass1 extends
AsyncTask<Void, Void, String> {
@Override
protected String doInBackground(Void... params) {
// TODO Auto-generated method stub
try {
UserFunctions usf = new UserFunctions();
Log.e(tag,"user_id"+user_id);
JSONObject json2 = usf.intrestlist(user_id);
JSONArray contacts = json2
.getJSONArray("interested_list");
for (int j = 0; j < contacts.length(); j++) {
Log.e(tag, "intrestedin forloop");
JSONObject c = contacts
.getJSONObject(j);
Requestencapsulation bean = new Requestencapsulation();
bean.setIntrest_id(c
.getString("interested_id"));
bean.setIntrest_name(c
.getString("interested_name"));
bean.setKey_status(c
.getString("status"));
if (c.getString("interested_info")
.equals("null"))
{
bean.setInterested_info("");
} else {
bean.setInterested_info(c
.getString("interested_info"));
}
offferList.add(bean);
}
k=offferList.size();
}
catch (Exception e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String result) {
new Serviceclass2().execute();
}
}
class Serviceclass2 extends
AsyncTask<Void, Void, String> {
@Override
protected String doInBackground(Void... params) {
// TODO Auto-generated method stub
try {
UserFunctions usf1 = new UserFunctions();
JSONObject json3= usf1.offerlistlist(user_id);
JSONArray contacts1 = json3.getJSONArray("offer_list");
for (int i = 0; i < contacts1.length(); i++) {
Log.e(tag,"INSIDE OFFERING LOOP");
JSONObject d= contacts1.getJSONObject(i);
Log.e(tag,"CREATED JSON OBJECT");
Requestencapsulation bean=new Requestencapsulation();
Log.e(tag,"OBJECT CREATED FOR OFFERINGENCAPSULATION");
bean.setIntrest_id(d
.getString("offer_id"));
Log.e(tag,
"offerid is::"
+ d.getString("offer_id"));
bean.setIntrest_name(d
.getString("offer_name"));
Log.e(tag,
"offer name is::"
+ d.getString("offer_name"));
bean.setKey_status(d.getString("status"));
Log.e(tag,
"status is"
+ d.getString("status"));
// if (d.getString("offer_info").equals(
// "null")) {
// bean.setInterested_info(d
// .getString("interested_info"));
// } else {
// bean.setInterested_info(d
// .getString("interested_info"));
//
// }
offferList.add(bean);
Log.e(tag,"process for bean1 completed");
;
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String result) {
new Serviceclass2().execute();
Context c = getParent();
m_adapter = new Intrested_in_adapter(
Transparent_alert.this,
R.layout.intrestedin, offferList);
mDialog = new AlertDialog.Builder(c);
mDialog.setTitle("Intrested In");
mDialog.setAdapter(m_adapter,
new DialogInterface.OnClickListener() {
public void onClick(
DialogInterface dialog,
int item) {
}
});
alertDialog = mDialog.create();
alertDialog.show();
}
}
intrestedin.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<CheckBox
android:id="@+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
/>
</LinearLayout>
Intrested_in_adapter.java
public class Intrested_in_adapter extends ArrayAdapter<Requestencapsulation>{
CheckBox checkbox;
CheckBox checkbox1;
private List<Requestencapsulation> alist;
private List<Offeringencapsulation> alist1;
public Intrested_in_adapter(Context context, int textViewResourceId) {
super(context, textViewResourceId);
}
public Intrested_in_adapter(Context context, int resource, List<Requestencapsulation> items) {
super(context, resource,items);
this.alist=items;
Log.e("Inside Constructor","list size is:"+alist.size());
}
@Override
public Requestencapsulation getItem(int position) {
return alist.get(position);
}
public long getId(int position)
{
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// ViewHolder mHolder;
Requestencapsulation p = getItem(position);
if (convertView == null) {
Log.e("inside convertview","inside convertview");
convertView = LayoutInflater.from(getContext()).inflate(R.layout.intrestedin, parent, false);
}
if (p != null) {
// mHolder = new ViewHolder();
checkbox=(CheckBox)convertView.findViewById(R.id.checkbox);
if(alist.get(position).getKey_status().equalsIgnoreCase("true"))
{
checkbox.setSelected(true);
}else{
checkbox.setSelected(false);
}
checkbox.setText(alist.get(position).getIntrest_name());
}
return convertView;
}
}
maifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.gatekeeper.dropswitch"
android:installLocation="auto"
android:largeHeap="true"
android:versionCode="3"
android:versionName="1.1" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission
android:name="com.example.gate.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.gate.permission.C2D_MESSAGE" />
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:allowBackup="true"
android:icon="@drawable/gate_logo"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.gate.Redirectclass"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:theme="@android:style/Theme.NoTitleBar"
android:name="com.example.gate.Userpage"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Guardpage"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Transparent_alert"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" >
</activity>
<activity
android:name="com.example.gate.Registerpage"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.ProfileActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Selectbuttonfromrequestclass"
android:screenOrientation="portrait">
</activity>
<activity
android:name="com.example.gate.Actionclass"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.TabGroup1Activity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Tabgroup2"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Tabgroup3"
android:screenOrientation="portrait" >
</activity>
<activity android:name="com.example.gate.MainActivity"
android:screenOrientation="portrait">
</activity>
<activity
android:name="com.example.gate.Home"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Homenext"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Family"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.FamilyMain"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Familyedit"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.GuestMain"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Guest"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Guestedit"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Services"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Addprovider"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Addservices"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Offering"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan" >
</activity>
<activity
android:name="com.example.gate.Interest"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Accesspreferences"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.ActionActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Messageclass"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Report"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Requestclass"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Notify"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Rsidenceinfo"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Latestservice"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Guardactiongroup"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Guardprofilegroup"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Guardinfogroup"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Otherresidence"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Directoryguardedit"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Guardaction"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.skype.raider.Main"
android:configChanges="keyboardHidden|orientation"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize" >
<intent-filter android:priority="0" >
<action android:name="android.intent.action.CALL_PRIVILEGED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="tel" />
</intent-filter>
</activity>
<activity
android:name="com.example.gate.Guardinfo"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Guardprofile"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.video"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Guard_message_class"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Guard_report_class"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Guard_notify_class"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Guard_request_class"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.guard_addnew_residence"
android:screenOrientation="portrait" >
</activity>
<receiver
android:name="com.example.gate.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<!-- Receives the actual messages. -->
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.example.gate" />
</intent-filter>
</receiver>
<service android:name="com.example.gate.GcmIntentService" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application>
</manifest>
我没有得到任何线索这样做。请任何人帮忙。任何帮助都将受到高度赞赏....
答案 0 :(得分:0)
如果你想使你的alertdialog透明,我不知道它是否可能,但是如下面显示的那样自定义警报对象更适合你,你只需要创建一个xml文件,设计与您当前的警报框完全相似,可以使其透明。
dialog = new Dialog(context);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dialog_profile_report);
dialog.setCanceledOnTouchOutside(false);
dialog.getWindow().setBackgroundDrawable(
new ColorDrawable(android.graphics.Color.TRANSPARENT));
dialog.show();
Button mainListView = (Button) dialog.findViewById(R.id.listview); // you can declare elements like this and can make onclick methods for these elements
答案 1 :(得分:0)
尝试让对话透明,就像这样
intrestedin.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@android:color/transparent"
答案 2 :(得分:0)
请将下面的代码放在风格
中 <style name="CustomAlert" parent="android:Theme.Dialog">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
<item name="android:backgroundDimEnabled">false</item>
<item name="android:background">@android:color/transparent</item>
</style>
<强> 代码: 强>
Dialog mDialog = new Dialog(baseApplication.getCurrentActivity(),
R.style.CustomAlert);
mDialog.setCancelable(true);
mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
mDialog.setContentView(R.layout.inflate_toast);
//you can set height width of dialog as well as position
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
Window window = mDialog.getWindow();
lp.copyFrom(window.getAttributes());
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
lp.gravity = Gravity.TOP;
window.setAttributes(lp);
mDialog.show();
在您的活动中xml:
将背景设置为listview,listview的分隔符和listview的夸大布局的透明色。
答案 3 :(得分:0)
<击> 取代击>
<击>alertDialog = mDialog.create();
alertDialog.show();
与
alertDialog = mDialog.create();
alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
alertDialog.show();
击> <击> 撞击>
<强>问题:强> 您的适配器正在膨胀行布局以在ListView中显示。正如您所看到的,它将在使用LayoutInflater进行充气时使用Parent容器进行引用。 它在创造一切透明的同时创造了问题。
选项1:
您应该考虑使用Dialog
代替AlertDialog
,并使用setContentView
选项2: 你会因为旧api而有一些缺点,但它会在新的api中起作用
替换
mDialog = new AlertDialog.Builder(c);
与
mDialog = (Integer.parseInt(android.os.Build.VERSION.SDK) < 11)? new AlertDialog.Builder(c) :new AlertDialog.Builder(c, android.R.style.Theme_Translucent);