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);
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.
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
There are a few questions already asking about this, but I'm not finding a solution. I have a LiveWallpaper that is using its own subclass of PreferenceFragment to specify preferences. The solution most often cited is to assure that setContentView() is called before findViewByID(). I am not calling setContentView() at all because I do not have a layout specified. This app originally implemented the preferences using the deprecated methods like PreferenceActivity.getPreferenceManager() and without using a layout and worked just fine. I am trying to bring the code up-to-date in using PreferenceFragment.
Am I required to have a layout and if so, what would I have when I don't really want one?
Or is there a another way to get/set the View?
public class SetPreferenceActivity extends Activity {
private CheckBox redCheckBox;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main); ???
redCheckBox = (CheckBox)findViewById(R.id.redCheckBox); // returns null
getFragmentManager().beginTransaction().replace(android.R.id.content, new LiveWallpaperPreferenceFragment()).commit();
}
}
You can create views dynamically :
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView textView = new TextView(this);
textView.setText("Hello");
setContentView(textView);//<----set the view !
}
}
I want to change the language in my app programatically.
The first onCreate(Bundle) method works and the images are displayed in chinese.
The second doesnt work. What do I have to insert in the "TODO" comment? I want to change the language AFTER the view was created and want to update it.
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TranslationHelper.changeLanguage(this, Locale.CHINESE);
setContentView(R.layout.main_activity);
doBindService();
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
TranslationHelper.changeLanguage(this, Locale.CHINESE);
// TODO recreate view to display chinese version
doBindService();
}
The first sample works because it changes locale before setContentView method is called. You need to insert changeLanguage before setContentView.
All views are already inflated after setContentView so changing locale at this point will have no effect. You need to update it manually if you want to change the language after the view was created.
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..