I have a custom alertdialog that inflates this custom layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/infoLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:theme="#style/AppTheme" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:weightSum="2" >
<TextView
android:id="#+id/infoVersionTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right|center"
android:text="#string/infoVersion"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/infoVersionTitleValue"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
<TextView
android:id="#+id/infoDetailText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/linearLayout1"
android:padding="10dp" />
</RelativeLayout>
I have this in my manifest file:
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
........
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
And I've got style.xml defined this way:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppTheme" parent="android:Theme.Light"></style>
</resources>
style.xml v11 defined like this:
<resources>
<style name="AppTheme" parent="android:Theme.Light"></style>
</resources>
And style.xml v14 defined like this:
<resources>
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar" />
</resources>
When running this on a 4.0.3 device it shows like this:
And running on a 2.3.3 device it shows like this:
On 2.3.3 devices, text is almost unreadable and I want to show white background (title bar included)
Is it possible to make the custom alertdialog show on all devices like it shows on 4.0.3?
I've saw this but cant't seem to figure it out.
Any solutions?
Try calling AlertDialog.Builder#setInverseBackgroundForced(true) when you create your dialog.
You can use ActionBarSherlock for this purpose
Check the description in Theming page for Dialog
To ensure compatibility for all devices:
setInverseBackgroundForced(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ? false
: true)
This makes sure devices below HoneyCromb display normally and devices below are inverted!
Here is an example:
final AlertDialog.Builder dialog = new AlertDialog.Builder(this)
dialog.setInverseBackgroundForced(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ? false
: true);
dialog.setMessage("Test Dialog!");
dialog.create().show();
See the docs:
http://developer.android.com/reference/android/app/AlertDialog.Builder.html#setInverseBackgroundForced(boolean)
Related
For some reasons when I launch the app in the splash activity and in the row activity, see images, there is a header bar with the name of the app "Baby Read".
I don't want the header there, how do I get rid of it?
Splash Activity
Row Activity
[![enter image description here][2]][2]
This is the splash layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/babyreadappsplash"
>
</LinearLayout>
And this is the row layout:
<?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"
>
<ImageView
android:id="#+id/icon"
android:layout_width="90px"
android:layout_height="90px"
android:layout_marginLeft="10px"
android:layout_marginRight="10px"
android:layout_marginBottom="10px"
android:layout_marginTop="10px"
android:src="#drawable/ic_launcher" >
</ImageView>
<TextView
android:id="#+id/label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#+id/label"
>
</TextView>
This is res/values/styles after adding the code suggested
[![enter image description here][3]][3]
And this is the manifest after adding the code suggested
Create a style for your splash Activity like this
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
</style>
after that set this style for your splash Activity in Manifest
<activity
android:name="activity name"
android:theme="#style/AppTheme.NoActionBar"
/>
Update
make your style like this
<style name="splashStyle" parent="Theme.AppCompat.Light.NoActionBar">
//add other attributes
</style>
if not work for you change the parent of your AppTheme to Theme.AppCompat.Light.ActionBar
You can use this in onCreate:
getSupportActionBar().hide();
No need to create anew theme (At least for this purpose)
Modify you app theme (Picture one)change parent="android:Theme.Holo.Light.DarkActionBar" for parent="android:Theme.Holo.NoActionBar"
On you manifest, in the application section (picture 2)add
android:theme="#style/AppTheme"
If by any change you are supporting APIs below 13 you can add
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
to your app theme rather than changing the parent.
As a side note I would advise moving from Holo themes to Appcompat or even Material, but that´s out of the scope of this question
One of my activities has suddenly changed its color in the statusbar. By default it's black, but now it's transparent, why?
I've marked around the bar with a circle. By default this is black
My XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerInside"
android:id="#+id/do2get"
android:src="#drawable/loading"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="30dp" />
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:indeterminateTint="#00796b"
android:id="#+id/progressBar"
android:layout_below="#+id/do2get"
android:layout_centerHorizontal="true"
android:indeterminateTintMode="src_in"/>
</RelativeLayout>
I think its all about your actitiy`s theme.
First of all check this links:
How to change the status bar color in android
How to change the background color of android status bar
Maybe your base theme has attribute "android:windowTranslucentStatus" = true or "colorPrimaryDark = #android:color/transparent" etc. So you need to create new one style like:
<style name="YourActivityTheme" parent="BaseAppTheme">
<item name="android:windowTranslucentStatus">false</item>
<item name="android:statusBarColor">#android:color/black</item>
</style>
and then set this style to current activity theme in AndroidManifest:
<aplication
....... >
.......
<activity
android:name=".chapters.home.YourNiceActivity"
android:theme="#style/YourActivityTheme">
<intent-filter>
...
</intent-filter>
</activity>
.....
</application>
I'm trying to write a general style.xml for my app.
I want all my EditText views to have certain styling, so I've done something like this:
<!-- Base application theme. -->
<style name="MyAppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:editTextStyle">#style/App_EditTextStyle</item>
</style>
<style name="App_EditTextStyle">
<item name="android:background" >#ff0000</item>
<item name="android:textColor">#00ff00</item>
<item name="android:layout_marginLeft">50dip</item>
<item name="android:height">50dip</item>
</style>
In the manifest i apply the theme:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/MyAppTheme" >
and here is the sample layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/main_layout">
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/editText"
android:text="Test" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/editText2"
android:text="Test2" />
</LinearLayout>
Everything is working fine except for the margin. For some reason it does not apply and i have to add it manually to the EditText. Am i missing something?
If you want to do it for all EditText widgets, then apply this to the LinearLayout tag:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/main_layout"
style="#style/MyAppTheme">
My applications minSdkVersion is 15. So the buttons in the application will get a light blue color when the user touches it. Later i added a custom title for the application. After that my application components color is changed to orange when the user touches it. I found that it is the problem with the custom title. How to solve it. I need the features of sdk version 15. Please see how i added the custom title bar.
My Manifest.
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/CustomTheme">
My style used for the custome title bar (custom_style.xml)
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomTheme" parent="android:Theme">
<item name="android:windowTitleSize">30dip</item>
</style>
</resources>
Activity code where it changes to the Custome title bar
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);
My title bar layout(window_title.xml)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="30dip"
android:background="#FF0000" >
<ImageView
android:id="#+id/header"
android:src="#drawable/ic_launcher"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="left"/>
<Switch
android:id="#+id/laodAutomatically"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="MirrorLink auto-connect"
style="#android:style/Theme.Holo"
android:layout_alignParentRight="true"
/>
</RelativeLayout>
Your theme should probably inherit from a theme, which is a theme for the SDK 15. There's a nice tutorial that will get you started with supporting various SDK versions with themes and styles. Hope this helps.
http://developer.android.com/guide/topics/ui/themes.html
Your theme should selectively inherit either Theme, or android:Theme.Light, depending on the platform version. Look towards the end of this page.
I have this nice dialog view I set my UserInputDialog class to:
<LinearLayout android:id="#+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:id="#+id/nameMessage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="What is your name Captain?"
>
</TextView>
<EditText
android:id="#+id/nameEditText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="18sp"
>
</EditText>
<LinearLayout android:id="#+id/LinearLayout02" android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_gravity="center_horizontal">
<Button
android:id="#+id/okButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="OK">
</Button>
<Button android:id="#+id/cancelButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel">
</Button>
</LinearLayout>
</LinearLayout>
I want my dialog to show up but for the background to not fade out. Is this possible? Cause the view that calls this dialog has a neato background I would like to be shown as a backdrop to the dialog.
I found this online:
<style name="doNotDim" parent="#android:style/Theme.Dialog">
<item name="android:backgroundDimAmount">0</item>
</style >
but not sure how to apply that to my dialog? I have a class called public class UserInputDialog extends Dialog implements OnClickListener. It sets its content view to the layout described above.
I think I am doing this all right, just not sure how to add that style so I can NOT fade the background.
Secondary question: Can you get new looks on your dialog (by say having an image or icon display with your text there) by using Themes?
You can also remove the dim effect by code with the following:
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
Create a res/values/styles.xml file and add this to it.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.DoNotDim" parent="android:Theme">
<item name="android:backgroundDimEnabled">false</item>
</style>
</resources>
And apply the theme to your activity.
<activity android:name=".SampleActivity" android:theme="#style/Theme.DoNotDim">
Create a custom style and place it in your values folder
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="YourCustomStyle" parent="android:Theme">
<item name="android:backgroundDimEnabled">false</item>
</style>
</resources>
To set a style to an individual dialog you can use
Dialog dialog = new Dialog(context, R.style.YourCustomStyle);
For displaying dialog like TrueCaller do this:
In styles.xml file.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="myBackgroundStyle" parent="android:Theme.Dialog">
<item name="android:backgroundDimEnabled">false</item>
</style>
</resources>
In AndroidManifest.xml do this:
<activity android:name=".SampleActivity" android:theme="#style/myBackgroundStyle">