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>
Related
Noob here, having an issue with the action bar in landscape mode (want to keep it in portrait mode).
I post a sample of my manifest xml file having tried the info in other threads.
<?xml version="1.0" encoding="utf-8"?>
<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">
<activity
android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
my styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Primary theme color of the app (sets background color of app bar) -->
<item name="colorPrimary">#ffcfcf</item>
<!-- Background color of buttons in the app -->
<item name="colorButtonNormal">#ff8383</item>
</style>
<style name="AppThemeNoActionBar" parent="AppTheme">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
a snippet from my land\activity_main.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:style="#style/AppThemeNoActionBar">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/love3"
android:scaleType="centerCrop"/>
...
I have tried changing the parent in styles.xml from AppTheme to Theme.AppCompat.Light to no avail.
portrait layout xml does not have android:style="#style/AppThemeNoActionBar"
Any pointers would be great!
Try this in onCreate function below setContentView
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
getSupportActionBar().hide();
}
you can do it like this,
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
else {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
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.
Adding UI elements to my activity changes nothing when app runs - I get an empty activity.
I've attached my activity layout, manifest and styles file.
Activity Layout:
<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"
android:id="#+id/activity_main"
android:clickable="false">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="text"
android:id="#+id/textView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="75dp"
android:visibility="visible"
android:editable="false" />
Manifest looks like:
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#mipmap/my_icon"
android:label="#string/app_name">
<activity
android:name=".MainActivity"
android:theme="#style/myTheme"
android:label=""
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Styles looks like:
<resources>
<style name="myTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowNoTitle">false</item>
<item name="windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
</style>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
</style>
make sure to use the right oncreate() method as we have two methods:
public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState)
and
protected void onCreate(#Nullable Bundle savedInstanceState)
What does your MainActivity look like? Have you used
setContentView(R.layout.main_activity)
in onCreate() ?
I have found the problem. Apparently a webView was declared
setContentView(webView);
In my main activity.
I came across the same issue when I started developing on android recently.
The problem was I had an infinite loop running in the onCreate(Bundle savedInstanceState) method of the activity.
Though all the elements were present in the layout, since the activity was entering an infinite loop after its created, no UI elements were rendered
Hope this helps
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