I make setting customtitle of alertdialog builder with a view that contains two webviews for animated gif and textview between them. the webviews are shown in the title of the alert dialog but the textview is missing.
here the view XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="75dp"
android:weightSum="1"
android:background="#android:color/background_dark">
<WebView
android:layout_width="wrap_content"
android:layout_height="75dp"
android:id="#+id/Title_webView1"
android:layout_weight="0.15"
android:layout_gravity="left" />
<TextView
android:id="#+id/titletextView"
android:layout_width="match_parent"
android:layout_height="75dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_gravity="center"
android:layout_weight="0.7"
android:textAlignment="center"
android:textIsSelectable="false"
android:visibility="visible"
android:gravity="center_vertical|center_horizontal"
android:inputType="none"
android:textColor="#d0d2d116"
android:text="test123"
android:singleLine="true"
android:textSize="32dp" />
<WebView
android:layout_width="wrap_content"
android:layout_height="75dp"
android:id="#+id/Title_webView2"
android:layout_weight="0.15"
android:layout_gravity="right" />
here the view function:
private View setCustomDialogTitle(String Title)
{
LayoutInflater inflater = getLayoutInflater();
View view = inflater.inflate(R.layout.embark_title, null);
TextView TitleText = (TextView) view.findViewById(R.id.titletextView);
TitleText.setText(Title);
WebView flashingLight1 = (WebView) view.findViewById(R.id.Title_webView1);
flashingLight1.loadUrl("file:///android_asset/flashlight751.gif");
WebView flashingLight2 = (WebView) view.findViewById(R.id.Title_webView2);
flashingLight2.loadUrl("file:///android_asset/flashlight752.gif");
return view;
}
and the function call:
AlertDialog.Builder alrtBuilder= new AlertDialog.Builder(this);
alrtBuilder.setCustomTitle(setCustomDialogTitle("Test123"));
the issue is with setting layout_width for the components and again setting them with weight.
so a small change in xml can help you out.The confusion in rendering will be the cause.
set all the layout_width attribute to "0dp"
android:layout_width="0dp"
for the three components, then it will bring you the exact look as you want. for some reference read this article, it really helps you to understand.
NB: tested and worked for your code
Related
I have an alertdialog with a custom layout, including a scrollview.
When the dialog appears, the scrollview is "cropped", and appears to be anchored to the top of the Screen, rather than the top of the dialog
I have searched SE for similar problems, and cannot find any.
Using a popup Window has exactly the same issue.
Here is my XML:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scroller"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/rock">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical"
android:padding="10dp">
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#drawable/scrollbutton"
android:padding="12dp"
android:text="Room Number"
android:textColor="#android:color/black"
android:textSize="22sp" />
<TextView
android:id="#+id/contents"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#drawable/scrollbutton"
android:gravity="center"
android:padding="12dp"
android:text="Here be Monsters" />
</LinearLayout>
</ScrollView>
And here is the dialog code:
LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.contents, null);
AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
alertDialog.setView(layout);
AlertDialog alert = alertDialog.create();
alert.requestWindowFeature(Window.FEATURE_NO_TITLE);
alert.show();
Window window = alert.getWindow();
window.setLayout((int)(screenWidth*.8), (int)(screenHeight*.8));
I have tried adding the ScrollView as the root_view in the inflater, and also adding a LinearLayout around the ScrollView and setting this as root_view, but this does not alter the results
You don't set parent to layout inflater. Let dialog manages view arranging DialogFragment
I have a stand-alone EditText and a ListView. Each item in the ListView also has two EditText fields. When I touch inside the ListView EditText, the stand-alone EditText steals the focus. This makes it impossible to edit any of the ListView EditText fields.
Name steals the focus from the other TextView elements inside the ListView
Here is the activity's XML, containing the stand-alone EditText and the ListView
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dip"
android:orientation = "vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginBottom="16dip" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dip"
android:layout_weight="1"
android:text="#string/name"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/editblindschedule_name"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="5"
android:ems="10"
android:inputType="text" />
</LinearLayout>
<ListView
android:id="#+id/listview_editblindschedule"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
And here is the ListView row 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" >
<TextView
android:id="#+id/editblindschedule_round"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"/>
<EditText
android:id="#+id/editblindschedule_small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="#string/small"
android:ems="4"
android:inputType="number"
android:layout_weight="4"
android:layout_marginRight="10dip"
android:text="#string/integer_zero"
android:gravity="center" />
<EditText
android:id="#+id/editblindschedule_big"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="#string/big"
android:ems="4"
android:inputType="number"
android:layout_weight="4"
android:layout_marginRight="10dip"
android:paddingRight="6dip"
android:text="#string/integer_zero"
android:gravity="center" />
<CheckBox
android:id="#+id/editblindschedule_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:checked="true" />
</LinearLayout>
Here is the Java code
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edit_blind_schedule);
...
adapter = new BlindAdapter(this, blindSchedule.getBlindLevels());
listView = (ListView) findViewById(R.id.listview_editblindschedule);
listView.setAdapter(adapter);
And finally, the adapter:
#Override
public View getView(int position, View convertView, ViewGroup parent)
{
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row = inflater.inflate(R.layout.listview_editblindschedule, parent, false);
if (!creating) { // Set default values.
TextView round = (TextView) row.findViewById(R.id.editblindschedule_round);
EditText small = (EditText) row.findViewById(R.id.editblindschedule_small);
EditText big = (EditText) row.findViewById(R.id.editblindschedule_big);
round.setText("" + (position + 1));
small.setText("" + blindLevels.get(position).getSmallBlind());
big.setText("" + blindLevels.get(position).getBigBlind());
}
return row;
}
The solution that worked for me was to put android:windowSoftInputMode="adjustPan" in the activity in the manifest. This was the only change necessary for me.
I don't like it but after digging ListView code I ended up by overriding the getFocusedChild() method and returning null as all other trials of flag combinations didn't get to a satisfactory solution.
Even if android:windowSoftInputMode="adjustPan" works adjusting pan leads to too much artifacts in my layout.
Beware overriding that method may lead to other unwanted behaviours so use it and test it comprehensively in all android versions you support and may be call super instead of returning null for android versions that does not/will have this problem.
I am designing an "about" menu for an app and have used the following code in an options menu to generate it:
case DIALOG_ABOUT:
builder = new AlertDialog.Builder(this);
Context context = getApplicationContext();
LayoutInflater inflater = (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.about_dialog, null);
builder.setView(layout);
TextView title = new TextView(this);
title.setText(R.string.about_title);
title.setGravity(Gravity.CENTER);
title.setTextSize(20);
builder.setCustomTitle(title);
builder.setPositiveButton("OK", null);
dialog = builder.create();
break;
I have created two different views for the about menu - for both horizontal and vertical viewings.
When displaying vertically, the about menu looks fine, but when displaying horizontally the bottom part of the text is being cut off. I am using the LayoutInflator and View controls without having that much knowledge about how they work, so I assume they are currently filling to some Android-specified size.
How can I create the dialog to take up the whole screen, or at least 90% of it?
Edit - My layouts looked like this:
Vertical Layout:
<ImageView
android:id="#+id/imageView1"
android:layout_width="120dp"
android:layout_height="120dp"
android:src="#drawable/icon" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="#string/game_name"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="#string/game_description"
android:textAppearance="?android:attr/textAppearanceMedium" />
Horizontal Layout:
<ImageView
android:id="#+id/imageView1"
android:layout_width="120dp"
android:layout_height="120dp"
android:src="#drawable/icon" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="#string/game_name"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="#string/game_description"
android:textAppearance="?android:attr/textAppearanceMedium" />
You may call the following on your dialog to fill entire space.
dialog.getWindow().setLayout(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
I use DraggableGridView to create a ViewGroup, and I want to add my custom view into it.
Below is my custom layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/Green"
android:gravity="center_horizontal"
android:orientation="vertical" >
<ImageView
android:id="#+id/item_img"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:padding="10dp"
android:scaleType="fitCenter"
android:src="#drawable/default_avatar" />
<TextView
android:id="#+id/item_name"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/Gray"
android:gravity="center"
android:text="Name" />
</LinearLayout>
As you can see, the background color of LinearLayout should be green, which is displayed correctly in the ViewGroup.
However, the ImageView and the TextView aren't displayed on the screen, neither even the background color of the TextView.
And this is my code to add the custom view:
LayoutInflater vi = (LayoutInflater) this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = vi.inflate(R.layout.item, null);
TextView textView = (TextView) v
.findViewById(R.id.item_name);
textView.setText(contact.getName());
textView.setTextColor(Color.WHITE);
gridView.addView(v);
What's the problem? Thank you.
I'm having problems inflating an AlertDialog with a custom XML. The problem is that it doesn't respect the width/height I've specified.
volume.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingLeft="6dp" android:gravity="center"
android:layout_gravity="center_horizontal" android:orientation="vertical"
android:layout_height="wrap_content" android:layout_width="250dip"
android:id="#+id/layoutRoot">
<TextView android:layout_width="wrap_content"
android:layout_gravity="left" android:id="#+id/textView1"
android:layout_height="wrap_content" android:text="Volume:"
android:layout_marginBottom="10dp" android:textSize="22dp"
android:layout_marginTop="10dp"></TextView>
<SeekBar android:layout_height="wrap_content"
android:layout_width="fill_parent" android:id="#+id/volumeBar"
android:minHeight="10dp" android:maxHeight="15dp" android:paddingLeft="10dp"></SeekBar>
<TextView android:layout_width="wrap_content"
android:layout_gravity="left" android:layout_height="wrap_content"
android:layout_marginBottom="10dp" android:textSize="22dp"
android:text="20%" android:id="#+id/volumeText"></TextView>
</LinearLayout>
Code:
Builder alertbox = new AlertDialog.Builder(this);
AlertDialog alertDialog;
LayoutInflater mInflater = (LayoutInflater) this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View VolumeView = mInflater.inflate(
R.layout.volume, (ViewGroup) findViewById(R.id.layoutRoot));
alertbox.setView(VolumeView);
alertDialog = alertbox.create();
alertDialog.show();
Your problem may be the layoutRoot you are providing as the second parameter of your call to mInflater.inflate(). This will affect the layout of the XML file being inflated.
Your question needs more information for anyone to give a better answer than this.