I have themes file to apply all of my buttons. The following coding is in my themes file.
<style name="CustomButton" parent="#android:style/Widget.Holo.Light.Button">
<item name="android:textSize">14sp</item>
<item name="android:layout_width">72dp</item>
<item name="android:layout_height">32dp</item>
<item name="android:background">#drawable/button_selector</item>
</style>
<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:buttonStyle">#style/CustomButton</item>
</style>
In the #drawable/button_selector
<selector>
<item android:drawable="#drawable/btn_bg">
<shape>
<size android:width="72dip" android:height="32dip"/>
<stroke
android:width="1dp"
android:color="#992f2f" />
<corners
android:radius="3dp" />
</shape>
</item>
</selector>
In my layout file
<Button android:id="#+id/savebtn"
android:layout_width="wrap_content" android:layout_marginRight="15dip"
android:layout_height="wrap_content"
android:text="Save"/>
My problem is that the button width and height didn't change. When I set layout_with(72dp) and layout_height(32dp) in the savebtn directly, it works. I have already defined themes file in application tag. I don't want to set all of my buttons like that. I would like to know any suggestions or idea?
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myproject"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="15" />
<application
android:label="#string/app_name"
android:theme="#style/MyTheme">
<activity
android:name=".activity.setting.SettingActivity"
android:label="#string/menu_settings" >
</activity>
<activity
android:name=".activity.setting.AboutActivity"
android:label="#string/app_name" >
</activity>
<activity
android:name=".activity.DetailsActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I tested exactly your code and it worked.
Did you add the following on your AndroidManifest.xml?
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/MyTheme" >
If still doesn't work, please post your manifest!
Also pay attention that if you are setting another theme on your activity, it will override the application theme!
Related
I'm creating a new app using Flutter and wanted to add a custom image on the initial splash screen.
The image appears on the splash screen, however for about half a second it appears stretched which does not look very good.
I've been searching but have struggled to find anyone with the same issue.
Any ideas?
I have tried giving a variable size image using mipmap but produces the same result.
launch_background.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/green" />
<item>
<bitmap
android:gravity="center_horizontal"
android:src="#drawable/ic_logo"
android:tileMode="disabled"/>
</item>
</layer-list>
style.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="LaunchTheme" parent="#android:style/Theme.Black.NoTitleBar">
<item name="android:windowBackground">#drawable/launch_background</item>
<item name="android:windowFullscreen">false</item>
</style>
<color name="green">#b7dd05</color>
</resources>
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.flutter_app">
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:label="flutter_app"
android:icon="#mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="#style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize"
android:screenOrientation="portrait">
<!-- This keeps the window background of the activity showing
until Flutter renders its first frame. It can be removed if
there is no splash screen (such as the default splash screen
defined in #style/LaunchTheme). -->
<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
I don't mind the image taking a second the render in, but having it stretched first is not ideal.
You'll need to provide an image with all the possible sizes (mdpi, hdpi, xhdpi, etc) to have the correct size for every screen size and use this drawable:
<?xml version="1.0" encoding="utf-8" ?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#android:color/holo_green_dark" />
<padding
android:left="0dp"
android:top="0dp"
android:right="0dp"
android:bottom="0dp" />
</shape>
</item>
<item
android:gravity="center"
android:drawable="#drawable/logo_splash">
</item>
</layer-list>
This will be my styles:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="SplashScreen" parent="AppTheme">
<item name="android:windowBackground">#drawable/splash</item>
<item name="android:windowFullscreen">false</item>
</style>
</resources>
finally this will be my AndroidManifest.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.marianozorrilla">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity
android:name=".MainActivity"
android:theme="#style/SplashScreen">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
</application>
</manifest>
The result of all these will be the following:
In my case, the logo_splash.png has a size of 200px-200px size. If you really want to handle the size in DP you'll need to have a minimum API 23:
<?xml version="1.0" encoding="utf-8" ?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#android:color/holo_green_dark" />
<padding
android:left="0dp"
android:top="0dp"
android:right="0dp"
android:bottom="0dp" />
</shape>
</item>
<item
android:gravity="center"
android:drawable="#drawable/logo_splash"
android:width="100dp"
android:height="100dp">
</item>
</layer-list>
This one will look like this:
I am having the most frustrating issue with a new Activity. I created it in the "normal" way:
Right-Click -> New -> Activity -> Empty Activity
However I am getting this annoying error when I try to launch the activity:
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
I feel my question is different from the others on StackOverflow because I've done some poking around on StackOverflow as well as googling in general, but these errors seem to pop up when somebody tries to open a dialog box, not when they are simply trying to launch a new activity.
Here is my Activity Class ViewAllStudents.java:
public class ViewAllStudents extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_all_students);
}
}
I am getting the error on the setContentView(R.layout.activity_view_all_students); line.
My layout resource file activity_view_all_students.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/view_all_students_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="#layout/student_table_header" />
<ListView
android:id="#+id/student_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
My include file student_table_header.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="#color/DARKOLIVEGREEN"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:id="#+id/student_number_header"
style="#style/StdTableHeader"
android:layout_weight="1"
android:text="#string/student_number_header"/>
<TextView
android:id="#+id/student_id_header"
style="#style/StdTableHeader"
android:text="#string/student_id_header"/>
<TextView
android:id="#+id/student_location_header"
style="#style/StdTableHeader"
android:text="#string/student_location_header"/>
<TextView
android:id="#+id/student_status_header"
style="#style/StdTableHeader"
android:text="#string/student_status_header"/>
<TextView
android:id="#+id/student_delete_header"
style="#style/StdTableHeader"
android:text="#string/student_injuries_header"/>
<TextView
android:id="#+id/student_deleted_header"
style="#style/StdTableHeader"
android:text="#string/student_deleted_header"/>
<TextView
android:id="#+id/student_last_modified"
style="#style/StdTableHeader"
android:text="#string/student_last_modified_header"/>
</LinearLayout>
Finally, my styles resource file styles.xml:
<resources>
<style name="StdTableHeader">
<item name="android:textSize">14sp</item>
<item name="android:paddingLeft">4dp</item>
<item name="android:paddingRight">4dp</item>
<item name="android:paddingTop">2dp</item>
<item name="android:paddingBottom">2dp</item>
<item name="android:layout_weight">10</item>
<item name="android:layout_width">0dp</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textColor">#color/WHITE</item>
<item name="android:textStyle">bold</item>
<item name="android:textAllCaps">true</item>
<item name="android:gravity">center</item>
</style>
</resources>
My AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="my.package">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="#drawable/app_icon"
android:label="#string/app_name"
android:supportsRtl="true">
<activity
android:name=".main.MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar"
android:windowSoftInputMode="adjustPan|stateHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".forms.formOne"
android:label="#string/form_one_header"
android:theme="#style/AppTheme.NoActionBar"
android:windowSoftInputMode="adjustPan|stateHidden" />
<activity
android:name=".forms.formTwo"
android:label="#string/form_two_header"
android:theme="#style/AppTheme.NoActionBar"
android:windowSoftInputMode="adjustPan|stateHidden" />
<activity
android:name=".forms.formThree"
android:label="#string/form_three_header"
android:theme="#style/AppTheme.NoActionBar"
android:windowSoftInputMode="adjustPan|stateHidden" />
<activity
android:name=".main.AddStudent"
android:label="#string/title_activity_add_patient"
android:theme="#style/AppTheme.NoActionBar" />
<activity android:name=".main.ViewAllStudents"></activity>
</application>
</manifest>
Add this attribute
android:theme="#style/Theme.AppCompat.Light"
in the activity tag.
Or have the styles.xml like the following
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
</resources>
and in manifest add this attribute
android:theme="#style/AppTheme"
in the application tag.
Ok ... to make a long answer short, check your AndroidManifest.xml files. For some reason, AndroidStudio neglected to insert critical line:
android:theme="#style/AppTheme.NoActionBar"
AndroidStudio had inserted this line for all of my other activities that I have created, except for this one.
Thanks to all who took the time to help and who tolerated my ignorance.
i have been looking for solutions for hours. i'm trying to split my action bar but it keeps stacking up in the top-right corner.
this is my menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:balloonberry="http://schemas.android.com/apk/res-auto">
<item android:id="#+id/action_search"
android:icon="#drawable/ic_action_search"
android:title="#string/action_search"
balloonberry:showAsAction="always"/>
<item android:id="#+id/action_location_found"
android:icon="#drawable/ic_action_location_found"
android:title="#string/action_location_found"
balloonberry:showAsAction="always"/>
<item android:id="#+id/action_refresh"
android:icon="#drawable/ic_action_refresh"
android:title="#string/action_refresh"
balloonberry:showAsAction="always"/>
<item android:id="#+id/action_help"
android:icon="#drawable/ic_action_help"
android:title="#string/action_help"
balloonberry:showAsAction="always"/>
<item android:id="#+id/action_check_updates"
android:icon="#drawable/ic_action_refresh"
android:title="#string/action_check_updates"
balloonberry:showAsAction="always"/>
</menu>
this is my AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.zapp.exampleproject1" >
<uses-sdk android:minSdkVersion="17"></uses-sdk>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.AppCompat.Light"
android:uiOptions="splitActionBarWhenNarrow">
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="android.support.UI_OPTIONS"
android:value="splitActionBarWhenNarrow`" />
</activity>
</application>
</manifest>
any solutions???? (i'm using a android 4.3 phone)
Neither appcompat-v7, nor the native action bar on Android 5.0+, support the split action bar. That pattern was officially discontinued as part of the Material Design overhaul. If you want that capability, you will need to put your own Toolbar at the bottom of your activity.
I am getting two title bar has below ,i have designed a custom title bar with image and text and used styles.xml to set the theme.I have same titlebar for two screens with different text.
the code are has below
public class ReminderActivity extends Activity {
Context context;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.reminderlayout);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.reminderlayout);
ArrayList<GetReminder> list = (ArrayList<GetReminder>) getIntent().getSerializableExtra("reminderList");
System.out.println("size is >>>"+list.size());
}
}
xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="35dip"
android:gravity="center_vertical"
android:orientation="horizontal"
android:background="#drawable/formheader">
<ImageView
android:id="#+id/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_launcher"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Reminder Messages"
android:textColor="#android:color/black"
android:textStyle="bold" />
</LinearLayout>
manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.loginscreen"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name="com.example.sampleapp.MainActivity"
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="com.example.sampleapp.ItemActivity"
android:theme="#style/TitleBarTheme" />
<activity
android:name="com.example.sampleapp.ReminderActivity"
android:theme="#style/TitleBarTheme" > </activity>
</application>
</manifest>
and style.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="titleBarHeading" parent="#android:style/TextAppearance">
<item name="android:textSize">17sp</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">#444444</item>
</style>
<style name="CustomWindowTitleBarBG">
<item name="android:background">#323331</item>
</style>
<style name="TitleBarTheme" parent="android:Theme">
<item name="android:windowTitleSize">35dip</item>
<item name="android:windowTitleBackgroundStyle">#style/CustomWindowTitleBarBG</item>
</style>
</resources>
setContentView(R.layout.reminderlayout);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.reminderlayout);
You are using the same layout file for both the Content View and Title. Create a separate layout files for both
however my text color will not change it's color to black.
I don't know what the problem could be... do you have any idea?
<TextView
android:id="#android:id/empty"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textColorHint="#000000"
android:textSize="14sp"
android:color="#000000" >
EDIT:
My manifest is that:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.blabla.blabla"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="11" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
>
<activity
android:name=".blablabla"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
my styles.xml is empty
<resources>
</resources>
EDIT:
i think i solved my problem..
the solution: Android ListView Text Color
i aded a style:
<style name="ListFont" parent="#android:style/Widget.ListView"> <item name="android:textColor">#000000</item> <item name="android:typeface">sans</item> </style>
and added it in my manifest...
in my activity i used this:
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(), R.array.BlaBla, android.R.layout.simple_list_item_1);
i ask myself what exactly "android.R.layout.simple_list_item_1 does? - why my textColor did not worked and why it does work now with a seperate style - do i need to mention simple_list_item_1 then in my activity any more?
thx u guys