I am using a custom title bar for my all activities but i can use this in PreferenceActivity.
All i can do in PreferenceActivity is this:
#Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar);
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences3);
My title bar in preference activity stay always grey without any text but other activities works very well this code. What i can do to solve my problem??
put getWindow().... after super and addPreferencesFromResource... so order should be:
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences3);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar);
p.s. credits to original author #jeffrey-blattman following my previous answer here..
Related
I am having a confusion regarding setting of a background colour in my preference activity. My settingsactivity doen't have any layout.xml attached with it and thus generated everything from the headers.xml and preferences.xml. I used this answer in my onCreate method of my settingsactivity class.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setupActionBar();
this.getWindow().getDecorView().setBackgroundColor(0xFF111321);
}
Using this I can see the change in my preferences (sorry for the colour) but my headers headers stay the same. To change the background of my headers I have to write:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setupActionBar();
this.getWindow().getDecorView().setBackgroundColor(0xFF111321);
listView = getListView();
listView.setBackgroundColor(0xFF111321);
}
Also if I don't use getWindow() the opposite happens.
Why is this happening?
I hate writing duplicate code for the same functionality, is there any way to do the requirement with a single code.
N.B. getWindow() also works with my other activities.
I have a fragment that shows a camera preview and a button, and in the activity for the fragment I'm trying to hide the title bar, but it doesn't work. The title bar still shows. In the activity:
#Override
public void onCreate(Bundle savedInstanceState) {
// Hide the window title
requestWindowFeature(Window.FEATURE_NO_TITLE);
// Hide the status bar and other OS-level chrome
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
}
I'm following the book Android Programming: The Big Nerd Ranch Guide.
#Override
protected void onCreate(final Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// Make this activity, full screen
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
// Hide the Title bar of this activity screen
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
...
}
In manifest change this
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
When I use this code to make my activity with no title my app crashes, I have tried it using .xml or by coding
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main_menu);
}
I also tried:
getActionBar().hide();
MinSDK=14
TargetSDK:21
Any idea?
getSupportActionBar().hide();
did the trick
Is there some way to hide status bar and keep action bar visible?
Yes, there is.
You should set FLAG_FULLSCREEN in your onCreate method of Activity.
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
}
i have a editText, so how do i check if the editText contain like "http://www."?
Is this possible to see if a component contain a specific string?
Thank-you
PS. is it also possible to change android:theme(like no title) at runtime?
IIRC the titlebar needs to be removed in the Activity onCreate before you call setContentView.
I use
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
As for the text search use
String.contains("http://www");
For Example
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.i(tag, "onCreate");
main = this;
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);