Simple android app crash after start [closed] - android

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
I tried to make a simple android app, that will trigger webserver to open the gate, everything worked just fine till I made some design (not java) changes. Now I cant even start the app properly.
Please take a look and tell me if you have any ideas. It tried the apk # Galaxy S3 and Note 3
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="wstrends.brana" >
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#drawable/logo"
android:label="WS trends Gatekeeper"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="WS trends Gatekeeper" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Otevřít bránu"
android:id="#+id/button"
android:layout_below="#+id/password"
android:layout_centerHorizontal="true"
android:layout_marginTop="43dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Pro prokračování vložte heslo"
android:id="#+id/upper"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="29dp"
android:password="false"
android:textColor="#bc000000" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="#+id/password"
android:singleLine="true"
android:password="true"
android:autoText="false"
android:layout_below="#+id/upper"
android:layout_centerHorizontal="true"
android:layout_marginTop="39dp"
android:hint="Heslo" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:singleLine="false" />
</RelativeLayout>
styles.xml
<resources>
<!-- inherit from the material theme -->
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<!-- Main theme colors -->
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:textColorPrimary">#fff</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#CA0700</item>
</style>
</resources>
Thanks

Try changing your styles.xml to the following. The theme must be a descendant of Theme.AppCompat:
<resources>
<!-- inherit from the material theme -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Main theme colors -->
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="actionBarStyle">#style/MyActionBar</item> <!-- For support lib compat -->
<item name="android:textColorPrimary">#fff</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#CA0700</item>
</style>
</resources>

Solution:
no changes in styles.xml whatsoever, but a little change in MainActivity.java fixed this
From public class MainActivity extends ActionBarActivity to public class MainActivity extends Activity

Related

Android: Unwanted White Box at Top of Screen (toolbar?)

How do I get rid of the white box at the top of the android view? I cannot see anywhere in my code where I called something that created the toolbar, nor did I code it myself. It also exists above the view, not in it. I'm guessing there is some setting in the design view of the xml file that can toggle it? Thanks in advance!
** I should also include that it is only on this activity, and my other activities do not have this white bar at the top. Furthermore, the actionbar is the thin blue bar above the white car, so any code that involves manipulating the actionbar will not change the white bar's status. **
EDIT: XML Code is below
<?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:background="#drawable/bucket"
android:theme="#+id/BucketTheme2"
android:backgroundTint="#70FFFFFF"
android:backgroundTintMode="src_over">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow>
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:paddingBottom="5dp"
android:paddingTop="100dp"
android:text="Find a place to go around you!"
android:textColor="#ff000000"
android:textSize="18dp" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:onClick="randomButtonPressed"
android:text="RANDOMIZE"
android:textSize="20dp" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="#+id/bucketBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:onClick="bucketButtonPressed"
android:text="Bucket List"
android:textSize="20dp" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="#+id/searchLocationBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:onClick="searchButtonPressed"
android:text="Search by Location"
android:textSize="20dp" />
</TableRow>
</TableLayout>
</RelativeLayout>
EDIT 2: style.xml code for BucketTheme2 is below (I did not post it initially because it only sets colors):
<style name="BucketTheme2" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
Set theme for application or activity in Manifest.xml to remove action bar:
android:theme="#android:style/Theme.Holo.Light.NoActionBar"
Or add the following code in Activity in the onCreate method and import android.support.v7.app.ActionBar:
ActionBar actionBar = getSupportActionBar();
actionBar.hide();
Add the following theme to the style.xml
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
Then set this theme to the activity in manifest:
<activity
android:name=".MainActivity"
android:theme="#style/AppTheme.NoActionBar"/>
UPDATE: You can also set the theme as below:
<style name="BucketTheme2" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
Hope this helps.
Change your activity theme in manifest to Theme.AppCompat.Light.NoActionBar and you should be sorted
Add NoActionBar style in style.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowFullscreen">false</item>
<item name="android:windowContentOverlay">#null</item>
</style>
And add this theme to your activity from manifest,
<activity android:name=".YourActivity"
android:theme="#style/AppTheme"
>
</activity>
try
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
it should be before setContentView
Just try this in your style
<style name="BucketTheme2" parent="android:Theme.Holo.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
I ran into this same issue when using a template project that Android studio already set up. I noticed that in the activity_main.xml file there was unnecessary padding at the top once I changed to a theme of *.NoActionBar. If you remove android:paddingTop="?attr/actionBarSize" it should go away.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="?attr/actionBarSize"></androidx.constraintlayout.widget.ConstraintLayout>

Top bar for app not hiding android

I have an app and in the Login screen I have multiple ways to login like gmail, facebook and manual login. They all are working nicely but the problem arises when I try to hide the top bar which shows the app name. I know this has something to do with the theme in the manifest but I haven't set any. Please have a look at my code and see what I am doing wrong ...
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.spuck"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="23" />
<application
android:allowBackup="true"
android:icon="#drawable/the_spuck_4"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<activity android:name=".LoginActivity"/>
LoginActivity.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:facebook="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.spuck.LoginActivity"
style="#style/Red">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="94dp">
<Button
android:id="#+id/sign_in"
android:layout_width="260dp"
android:layout_height="35dp"
android:textSize="13dp"
android:text="Sign In"
android:textColor="#color/white"
android:textAllCaps="false"
android:background="#drawable/signin_button_login_activity"
android:gravity="center"
android:layout_below="#+id/login_button"
android:layout_alignLeft="#+id/sign_in_button"
android:layout_alignStart="#+id/sign_in_button"
android:layout_marginTop="33dp" />
<ImageView
android:id="#+id/app_name"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="#drawable/the_spuck_3_2"
android:background="#drawable/white_with_round"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp" />
<com.google.android.gms.common.SignInButton
android:id="#+id/sign_in_button"
android:layout_width="260dp"
android:layout_height="35dp"
android:layout_marginTop="41dp"
android:layout_below="#+id/app_name"
android:layout_centerHorizontal="true" />
<com.facebook.login.widget.LoginButton
android:id="#+id/login_button"
android:layout_width="255dp"
android:layout_height="60dp"
android:textColor="#ffffff"
android:layout_marginTop="10dp"
android:shadowColor="#000"
android:shadowDx="0"
android:shadowDy="0"
android:shadowRadius="10"
android:layout_below="#+id/sign_in_button"
android:layout_centerHorizontal="true" />
</RelativeLayout>
</RelativeLayout>
AppTheme.NoActionBar.xml
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="colorPrimary">#ff5050</item>
<item name="colorPrimaryDark">#ff5050</item>
</style>
Change the theme of the activity to NoActionBar :
<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="colorPrimary">#ff5050</item>
<item name="colorPrimaryDark">#ff5050</item>
</style>
As Nika said, his approach is absolutely correct. What you need to see is that there are 2 types of themes made. One for API 21 and above and the other for API 21 and below. What you need to do is to assign the theme he said to both versions since you want your app to work for both API conditions. See the code below and let me know if it helped ...
for API 21 and above:
<resources>
<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">#ff5050</item>
<item name="colorPrimary">#ff5050</item>
<item name="colorPrimaryDark">#ff5050</item>
</style>
</resources>
for API 21 and below:
<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="colorPrimary">#ff5050</item>
<item name="colorPrimaryDark">#ff5050</item>
</style>
Now to access this you need to change your manifest to this:
<activity android:name=".LoginActivity"
android:theme="#style/AppTheme.NoActionBar"/>
P.S if you are not sure on how to see the themes for their respective API hold the ctrl button and click on "AppTheme.NoActionBar" text, it will show you two fields where they are to be found and just edit both of them.

How can I theme my action bar to match this image?

I'm working on an app's UI and I want to get the action bar to look like this:
This is what it looks like right now:
This is my styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/sunshine_blue</item>
<item name="colorPrimaryDark">#color/sunshine_dark_blue</item>
</style>
<!-- Main activity theme -->
<style name="ForecastTheme" parent="AppTheme">
<item name="actionBarStyle">#style/ActionBar.Solid.Sunshine.NoTitle</item>
</style>
<!-- Detail activity theme -->
<style name="DetailTheme" parent="AppTheme">
<item name="actionBarStyle">#style/ActionBar.Solid.Sunshine.Title</item>
</style>
<!-- Settings activity theme -->
<style name="SettingsTheme" parent="AppTheme">
</style>
<!-- Main activity action bar styles -->
<style name="ActionBar.Solid.Sunshine.NoTitle" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="displayOptions">useLogo|showHome</item>
<item name="logo">#drawable/ic_logo</item>
</style>
<!-- Detail activity action bar styles -->
<style name="ActionBar.Solid.Sunshine.Title" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="displayOptions">useLogo|showHome</item>
<item name="logo">#drawable/art_clear</item>
</style>
<!-- style for item selected on phone -->
<style name="ForecastListStyle">
<item name="android:choiceMode">none</item>
</style>
</resources>
This is the layout file for my detail activity:
<!-- Master layout -->
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-condensed"
android:textSize="24sp"
android:id="#+id/detail_day_textview" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-condensed"
android:textSize="16sp"
android:textColor="#color/fragment_detail_grey"
android:id="#+id/detail_date_textview" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="16dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:textSize="96sp"
android:paddingStart="32dp"
android:paddingLeft="32dp"
android:id="#+id/detail_high_textview" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:textSize="48sp"
android:textColor="#color/fragment_detail_grey"
android:paddingStart="64dp"
android:paddingLeft="64dp"
android:id="#+id/detail_low_textview" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/detail_icon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="22sp"
android:textColor="#color/fragment_detail_grey"
android:id="#+id/detail_forecast_textview" />
</LinearLayout>
</LinearLayout>
<!-- Humidity, wind, pressure -->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:textSize="22sp"
android:layout_margin="2dp"
android:id="#+id/detail_humidity_textview" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:textSize="22sp"
android:layout_margin="2dp"
android:id="#+id/detail_pressure_textview" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:textSize="22sp"
android:layout_margin="2dp"
android:id="#+id/detail_wind_textview" />
</LinearLayout>
</ScrollView>
And this is my AndroidManifest.xml file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.sunshine.app" >
<!-- This permission is necessary in order for Sunshine to perform network access. -->
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:theme="#style/ForecastTheme"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".DetailActivity"
android:theme="#style/DetailTheme"
android:label="#string/title_activity_detail"
android:parentActivityName=".MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.android.sunshine.app.MainActivity" />
</activity>
<activity
android:name=".SettingsActivity"
android:label="#string/title_activity_settings"
android:theme="#style/SettingsTheme"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.android.sunshine.app.MainActivity" />
</activity>
<provider
android:authorities="com.example.android.sunshine.app"
android:name=".data.WeatherProvider" >
</provider>
</application>
</manifest>
I've tried a couple different things in the displayOptions but can't seem to get the logo and "Details" text to display at the same time. Also, is there any way to get the arrow to match? Or does this just depend on the API level?
Thanks for any help!
It's better to use menu item in toolbar/app bar.
in this way there will be no additional space or any dislocate item in action bar .
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity">
<item
android:id="#+id/action_search"
android:icon="#drawable/ic_action_search"
android:orderInCategory="100"
android:title="#string/action_share"
app:showAsAction="always" />
<item
android:id="#+id/action_share"
android:icon="#drawable/ic_action_share"
android:orderInCategory="101"
android:title="#string/action_search"
app:showAsAction="always" />
<item
android:id="#+id/action_settings"
android:orderInCategory="102"
android:title="#string/action_settings"
app:showAsAction="never" /> </menu>
And just remember using toolbar is much more easier for your purpose
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/ColorPrimary"
android:minHeight="?attr/actionBarSize">
</android.support.v7.widget.Toolbar>
Here's complete tutorial

Android: applying margins using general style doesn't work

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">

Android custom style/scheme is not applied correctly to button-textColor

I'm having trouble with applying a custom scheme(style) to certain views. I have defined my own style in res/values/styles.xml
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="myStyle1">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textColor">#color/red</item>
<item name="android:textColorHighlight">#color/blue</item>
<item name="android:textColorHint"> #color/fuchsia</item>
<item name="android:textColorLink">#color/olive</item>
<item name="android:typeface">serif</item>
</style>
<style name="AppTheme" parent="android:Theme.Light" />
</resources>
I have applied this style to the main activity of my simple test application, like this
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main"
android:theme="#style/myStyle1" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
.
.
.
</application>
The layout of the MainActivity contains a couple of buttons, some textViews, some of them have the style attribute spiecified explicitly, others should be inhertiting it from the whole activity.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/layout_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/silver"
android:orientation="vertical" >
<EditText android:id="#+id/edit_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:hint="#string/edit_message" />
<Button android:id="#+id/send_button"
style="#style/myStyle1"
android:text="#string/button_send" />
<Button android:id="#+id/relative_activity"
android:text="#string/rel_activitity_text"
android:onClick="startRelativeActivity"/>
<Button android:id="#+id/button_TTT"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:textColor="#color/red"
android:text="#string/button_TTT" />
<fragment android:name="my.firstapp.Fragment1"
android:background="#color/red"
android:id="#+id/list"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
As far as I can tell, everything in the activity should be stylized according to the style I ahve defined, however, this is what I get
As you can see, only the buttons with the specified style have their text in red, the other two don't. However, even the white buttons get the correct font from the scheme, so at least some of it is being applied. Why not all of it? Any help would be appreciated, I'm thoroughly confused.
If you want a global style for all your buttons you need to do something like this.
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="myStyle1">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textColor">#color/red</item>
<item name="android:textColorHighlight">#color/blue</item>
<item name="android:textColorHint"> #color/fuchsia</item>
<item name="android:textColorLink">#color/olive</item>
<item name="android:typeface">serif</item>
</style>
<style name="AppTheme" parent="android:Theme.Light">
<item name="android:buttonStyle">#style/myStyle1</item>
</style>
</resources>
In your android manifest you should set the theme...
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main"
android:theme="#style/AppTheme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
.
.
.
</application>
You can do the same thing for checkboxs etc. More information from this link.
http://developer.android.com/reference/android/R.attr.html
Also I tested this on the following layout. All 3 buttons should have red text.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/layout_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffaaaaaa"
android:orientation="vertical" >
<EditText android:id="#+id/edit_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:hint="edit_message" />
<Button android:id="#+id/send_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="button_send" />
<Button android:id="#+id/relative_activity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="rel_activitity_text"
android:onClick="startRelativeActivity"/>
<Button android:id="#+id/button_TTT"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:textColor="#ffff0000"
android:text="button_TTT" />
<!--<fragment android:name="my.firstapp.Fragment1"
android:background="#00ff0000"
android:id="#+id/list"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />-->
</LinearLayout>

Categories

Resources