Ad
Android: The Location Of Title For Alert Dialog Fall Below The Line
I am showing an alert dialog when one of the item in list view is clicked. Everything is fine except the location of title for the dialog is wrong as shown in the image below. Why the title is located below the line instead of above the line?
Code of alert dialog
ListView listView = (ListView)findViewById(R.id.listView);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
final AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this,
android.R.style.Theme_Holo_Light_Dialog);
View view2 = getLayoutInflater().inflate(R.layout.dialog,null);
builder.setView(view2);
builder.setTitle("Edit")
.setCancelable(false)
// Add action buttons
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
//
refreshData();
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
})
.setIcon(android.R.drawable.ic_menu_edit)
.show();
}
});
Layout of alert dialog
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/dialog_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp">
<EditText
android:id="@+id/edittext_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Date"
android:inputType="text" />
<EditText
android:id="@+id/edittext_point"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Point"
android:inputType="numberSigned" />
<EditText
android:id="@+id/edittext_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Description"
android:inputType="text" />
</LinearLayout>
Ad
Answer
You're using a deprecated style for the dialog. Try this:
final AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
This is working fine for me.
EDITS
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
...
<item name="alertDialogTheme">@style/AlertDialogStyle</item>
...
</style>
<style name="AlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="colorAccent">#c0ff00</item>
<item name="android:titleTextStyle">@style/MyTextStyle</item>
</style>
Ad
source: stackoverflow.com
Related Questions
- → should I choose reactjs+f7 or f7+vue.js?
- → Phonegap Android write to sd card
- → Local reference jquery script in nanohttpd (Android)
- → Click to navigate on mobile devices
- → How to allow api access to android or ios app only(laravel)?
- → Access the Camera and CameraRoll on Android using React Native?
- → React native change listening port
- → What is the default unit of style in React Native?
- → Google play market autocomplete icon
- → Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of `ListView`
- → Using Laravel with Genymotion
- → react native using like web-based ajax function
- → react native pdf View
Ad