Activity with Dialogfragment is always in the middle - android

The image above is my current activity with a dialog fragment. as you can see dialog is in the middle of the screen but it want it to look something like in google maps where when I click on the button the dialog appears near the button:
=>
As you can see in google maps the dialog is not in the middle its near the selected button. This is my code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/edit_name"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="vertical">
<TextView
android:id="#+id/lbl_your_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Your name" />
<EditText
android:id="#+id/txt_your_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionDone"
android:inputType="text" />
</LinearLayout>
Which looks like this:
As you can see when I edit my dialogfragment the edittext and textview are on the top of the screen but for some reason when I deploy the app they are in the middle.

Related

Set Done Button on Kotlin DialogFragment with multi choice Items

I have a DialogFragment with multi chose style, which means it does not dismiss on select/deselect. The only way to dismiss it seems to be to click on the device Back button.
Im finding it strange to have click the device back button to dismiss the dialog. Is there a way to add a Done button to the dialog, next to the title?
Its quite simple actually, I'm extending the theoretical answer here:
Create your custom layout eg as myLayoutTitle.xml:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/select_type_title_container"
android:background="#f6f6f6">
<TextView
android:layout_width="wrap_content"
android:layout_height="50dp"
app:layout_constraintLeft_toLeftOf="#+id/select_type_title_container"
app:layout_constraintTop_toTopOf="#+id/select_type_title_container"
android:text="#string/menu_types"
android:layout_gravity ="center_vertical"
android:gravity="center_vertical"
android:textStyle="bold"
android:textSize="20dp"
android:id="#+id/select_types_textview"/>
<Button
android:layout_width="wrap_content"
android:layout_height="40dp"
app:layout_constraintRight_toRightOf="#+id/select_type_title_container"
app:layout_constraintTop_toTopOf="#+id/select_type_title_container"
android:layout_margin="5dp"
android:text="Done"
android:textColor="#color/colorPrimary"
android:id="#+id/done_select_types"
android:layout_gravity ="center_vertical"/>
</androidx.constraintlayout.widget.ConstraintLayout>
The on your dialog builder
builder.setCustomTitle(activity?.layoutInflater?.inflate(R.layout.myLayoutTitle, null))

Android: Custom AlertDialog has different text color

I created a custom layout for an AlertDialog, and it works fine,
But i have a problem with the text style of my layout.
This is the layout for my alertDialog:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/namedialoglable"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/profilename" />
<EditText
android:id="#+id/namedialoginput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/namedialoglable"
android:layout_marginTop="24dp"
android:ems="10"
android:selectAllOnFocus="true"
android:text="#string/defaultname" >
<requestFocus />
</EditText>
</RelativeLayout>
The problem is that the text into the default AlertDialog is white, and in my custom dialog is black. I just want to use the same color used into other AlertDialog.
How to do that?
EDIT
To be more clear:
I want to keep the father text color, not force my custom dialog color to be white. I think that AlertDialog use system color, so my alert need to keep the same color
Why wont you just apply:
android:textColor="#android:color/white"
to the Views you want with while text color.
Also look into styles and themes to achieve what you wnat:
http://developer.android.com/guide/topics/ui/themes.html#PlatformStyles
Ok in my case, i found another solution.
Since my need is to have only a message and an input text into the dialog box, the best solution is to create a layout with only an EditText, like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<EditText
android:id="#+id/namedialoginput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="24dp"
android:ems="10"
android:selectAllOnFocus="true"
android:text="#string/defaultname" >
<requestFocus />
</EditText>
</RelativeLayout>
And for the message text, using the builder method: setMessage:
builder.setView(content)
.setTitle("Profile Name")
.setMessage(R.string.profilename);
In that way, i am sure that i keep the other dialog boxes format.

When i focus on edit text with numeric input type, standart qwerty keyboard pops up

I have set my EditText field like this:
<EditText
android:inputType="number"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:id="#+id/editText" android:layout_gravity="center"
/>
When I click on that Edittext, correct numeric input keyboard shows up, but then immediately is replaced by the standard keyboard. If I click again, numeric keyboard appears and is not replaced by the standard keyboard. This happens in dynamically generated ListView, if that affects anything, and happens in both the emulator and the phone (samsung galaxy note). How can I prevent the standard keyboard from appearing?
Here is the actual code:
public class Delivery extends Activity {
ListView deliveryTipes;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.delivery_main);
deliveryTipes=(ListView) findViewById(R.id.tasksID);
String[] deliveryTipesList = getResources().getStringArray(R.array.tasks);
deliveryTipes.setAdapter(new ArrayAdapter<String>(this, R.layout.delivery_line,R.id.taskName, deliveryTipesList));
}
}
delivery_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tasksID" android:layout_gravity="center" android:padding="10dp"/>
</LinearLayout>
delivery_line.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:paddingLeft="10dp" android:paddingRight="10dp">
<TextView
android:layout_width="130dp"
android:layout_height="wrap_content"
android:text="Task Name"
android:id="#+id/taskName" android:layout_gravity="left|center_vertical" android:textStyle="bold"/>
<Space
android:layout_width="50dp"
android:layout_height="fill_parent"
android:id="#+id/space"/>
<EditText
android:inputType="number"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:id="#+id/editText" android:layout_gravity="center"
/>
</LinearLayout>
This kind of problems are very annoying. The short story is that by default a ListView is meant to simply show items, and optionally select them.
ListView doesn't assume its children to be focusable, it handles the focus by itself and triggers the appropriate listeners. When you start putting focusable widgets in a ListView, things soon get wild. Post the actual code, and you'll have more chances to get help.

Adding an EditText to jfeinstein sliding menu

I am working on an android project and I am making use of jfeinstein sliding menu library, library can be located at https://github.com/jfeinstein10/slidingmenu.
I have got the library working fine and have amended my code to make it work with other components, not just TextViews, such as Switches. I am now trying to add an EditText to the menu so that the user can enter directly in the box without having to switch activities.
I have it so I have a called MenuAdapter which extends ArrayAdapter. This then has a series of constructors which, based on the constructor and what values are passed into, determine which control is added to the sliding menu. The EditText is being added to the sliding menu and the hint is being sent, and when I tap on the edit text the keyboard is displayed but if I type anything, its not shown in the EditText. However, oddly, if I long press on the edit text and click paste, I can view the content that is pasted so its just typing that's not working.
Below is the XML layout, each component is hidden using the visibility set to gone and then is set to be displayed dependent on the constructor that was used.
<?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="50dp"
android:orientation="horizontal" >
<ImageView
android:id="#+id/row_icon"
android:paddingLeft="25dp"
android:layout_width="50dp"
android:layout_height="50dp"
android:padding="10dp"
android:visibility="gone" />
<TextView
android:id="#+id/row_title"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:padding="10dp"
android:text="Medium Text"
android:textAppearance="#android:style/TextAppearance.Medium"
android:visibility="gone"
android:textColor="#color/White" />
<Switch
android:id="#+id/row_switch"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:padding="10dp"
android:visibility="gone"
android:textColor="#color/White"/>
<EditText
android:id="#+id/row_edittext"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:padding="10dp"
android:visibility="gone"
android:textColor="#android:color/white" />
</LinearLayout>
Below is the code for how the EditText is being addd to the menu.
case EDITEXT:
EditText editText = (EditText)convertView.findViewById(getItem(position).viewID);
editText.setHint(getItem(position).hint);
editText.setEnabled(true);
editText.setVisibility(View.VISIBLE);
break;
Thanks for any help you can provide.

How to embed a View (with Buttons, etc.) inside an EditText?

I'm trying to figure out how to embed things, other than Drawables, inside an EditText widget. Specifically the example I'm thinking of is from the Google Buzz widget:
screenshot
(no inline image, sorry, I'm a newb)
It appears to the casual observer that there's an entire layout object pinned to the bottom of the EditText, containing an ImageView, a TextView, and a Button.
Anyone have any idea how to pull this off? Or do we think this is a custom subclass of EditText?
The EditText + Button + ... it's a FrameLayout with the EditText with fill_parent and the Buttons with layout_gravitiy:"bottom". Something like this:
<?xml version="1.0" encoding="utf-8"?> <!-- Main Layout (may be relative or whatever --> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- Layout for edittext and button -->
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:lines="5"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_margin="5dip"
android:text="Overflow"/>
</FrameLayout>
<!-- More layouts ..... --> </RelativeLayout>
you can use frame layout for embed Button in EditText,here i give sample code for embed TextView in EditText,just change the TextView as Button
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="40px"
android:layout_y="35px"
>
<EditText android:id="#+id/twt_post_content" android:layout_gravity="center_vertical"
android:layout_width="320dp" android:layout_height="140dp"
android:paddingTop="5dp" android:imeOptions="actionDone"
android:gravity="left" android:focusableInTouchMode="true"
android:maxLength="140" android:ellipsize="end" />
<TextView
android:text="123"
android:paddingLeft="270dp"
android:paddingTop="100dp"
android:layout_alignParentRight="true"
android:id="#+id/twt_content_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/red"
android:layout_gravity="center"
android:background="#color/transparent"/>
</FrameLayout>
I think that what they have done here is create a background for their layout that looks like an EditText. Then they added an EditText with the background turned off and come Buttons.

Categories

Resources