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
Related
When I normally create a new project, the activities have toolbars on top like this:
But somehow, I'm a noob so I managed to somehow delete this action bar by modifying the styles xml the Activity and the manifest. So now it's a fullscreen activity, even when I use DarkActionBar as parent in styles:
Here my files:
Styles.xml:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.swagdev.app.swagpoints">
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.CAMERA" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Map"/>
</application>
Activity:
<?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:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.swagdev.app.swagpoints.MainActivity">
<com.journeyapps.barcodescanner.BarcodeView
android:layout_width="300dp"
android:layout_height="300dp"
app:zxing_use_texture_view="true"
android:id="#+id/scanner"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/location_field"
android:textSize="30sp"
android:layout_below="#+id/scanner"
android:layout_centerHorizontal="true"
android:layout_marginTop="45dp" />
<TextView
android:text="Scan Sticker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tvh"
android:textSize="30sp"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true" />
<nl.psdcompany.duonavigationdrawer.views.DuoDrawerLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/drawer"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true">
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:tag="content"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:tag="menu"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
</FrameLayout>
</nl.psdcompany.duonavigationdrawer.views.DuoDrawerLayout>
</RelativeLayout>
SO now my toolbar is gone. How do i need to modify styles or activity or manifest to get it back?
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.
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
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>
I have a tabhost and there is an activity inside. I want this activity to have customized title bar so I used the following code. But it gives the error Cannot combine custom titles with other titles features. I look at the file and see only one theme applied to it, I am not sure why this is happening... Any idea? I am also using dialogtheme for other activities in my tabhost, but I think that is fine because I am applying my custom theme only to one Activity(which is named startActivity).
Manifest:
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".MainTabActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
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=".StartActivity"
android:label="#string/app_name"
android:theme="#style/CustomTheme" //this is the Custom title bar theme for this activity
android:screenOrientation="portrait" >
</activity>
Activity onCreate():
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); //error happned here
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);
super.onCreate(savedInstanceState);
Log.i(TAG, "onCreate()");
setContentView(R.layout.startactivity);
window_title.xml in layout folder:
<?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="35dip"
android:gravity="center_vertical"
android:paddingLeft="5dip"
android:background="#323331">
<ImageView
android:id="#+id/header"
android:src="#drawable/ic_launcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
Finally, the #style:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomWindowTitleBackground">
<item name="android:background">#323331</item>
</style>
<style name="CustomTheme" parent="android:Theme">
<item name="android:windowTitleSize">35dip</item>
<item name="android:windowTitleBackgroundStyle">#style/CustomWindowTitleBackground</item>
</style>
</resources>