我正在Android Jelly Beans OS上创建一个警告对话框.一切都运作良好,但我想要的是,而不是警报对话框的黑色背景,我想要一个透明的背景.我在stackoverflow上阅读了很多文章和用户的问题,但没有一个能帮助我.
这是我的代码:
AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.CustomAlertDialog);
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog1, int which) {
gActivityResult = REQUEST_PICK_CONTACT;
onResume();
return;
} });
builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog1, int which) {
return;
} });
View view = getLayoutInflater().inflate(R.layout.alert_dialog, null);
builder.setTitle(R.string.gender_age);
builder.setInverseBackgroundForced(false);
builder.setView (view);
dialog = builder.create ();
Run Code Online (Sandbox Code Playgroud)
这是我的CustomAlertDialog,它在res/values/styles.xml中定义
<style name="CustomAlertDialog" parent="@android:style/Theme.Dialog">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:windowFrame">@null</item>
<item name="android:windowIsFloating">true</item>
<item …Run Code Online (Sandbox Code Playgroud) android android-layout android-alertdialog android-4.2-jelly-bean
我阅读了Why does LayoutInflaterignore thelayout_width andlayout_heightlayoutparameters I've指定的答案?并想确保我理解附加到根的作用。基本上如果你这样做
inflater.inflate(int idOfLayoutFile, ViewGroup parent, boolean AttachToRoot)
Run Code Online (Sandbox Code Playgroud)
假设父级不为空
从我的答案中得到的是,附加到根只会影响 inflate 方法的返回类型。也就是说,如果attachToRoot是true,方法将返回父级,如果是false,该方法将返回资源 id 指定的 XML 文件的根视图。我在这里有正确的想法还是我错过了什么?
我正在研究一个项目,我正在将GUI转换为样式表.我使用布局,然后使用样式表的横向/纵向集.我使用充气器来扩充布局,因为我正在动态添加和删除内容,并且视图本身是由我的代码插入的应用程序动态创建和销毁的.
myView = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.bearing_layout, parentView, false);
Run Code Online (Sandbox Code Playgroud)
错误:Java.Lang.RuntimeException:二进制XML文件,第2行:您必须提供layout_width属性.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/bearing_overall_layout">
<LinearLayout
style = "@style/bearing_header_layout">
<TextView android:id="@+id/header"
style = "@style/bearing_header"
android:background="@drawable/transparentbackground"
android:text="@string/bearing_title" />
</LinearLayout>
<RelativeLayout style="@style/BearingSelectListContainer"
android:id="@+id/top_view">
<LinearLayout
style="@style/BearingSelectList_linear_layout">
<TextView style="@style/BearingSelectListTitle"
android:id="@+id/title"
android:text="@string/bearing_title" />
<ScrollView android:id="@+id/listScroller"
style="@style/bearing_list_scroller">
<LinearLayout
style="@style/bearing_scroll_list_linear_layout" >
<LinearLayout android:id="@+id/pointList"
style="@style/bearing_point_list">
</LinearLayout>
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal">
<Button style="@style/BearingSelectListButton" android:id="@+id/view" android:text="@string/view_button" />
<Button style="@style/BearingSelectListButton" android:id="@+id/my_loc" android:text="@string/my_loc_button" />
<Button style="@style/BearingSelectListButton" android:id="@+id/center" android:text="@string/center_button" />
<Button style="@style/BearingSelectListButton" android:id="@+id/exit" android:text="@string/exit_button" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
样式表:
<resources>
<style name="bearing_overall_layout">
<item name="android:orientation">vertical</item> …Run Code Online (Sandbox Code Playgroud) 我可以知道
public View getView(int position, View view, ViewGroup parent){
if (view ==null)
view = getLayoutInflater().inflate(R.layout.listview_item, parent, false);
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以向我解释谢谢!