I managed to change my preference activity's background color, but when I focus/scroll it, it blinks. Please help me solve this. This is how i change my background...
public class ConfigActivity extends PreferenceActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preference);
findViewById(android.R.id.list).setBackgroundColor(getResources().getColor(R.color.gray));
}
}
Use android:cacheColorHint="#00000000" in your layout.
See also http://android-developers.blogspot.com/2009/01/why-is-my-list-black-android.html
Related
Give your buttons some behavior.
change the foreground color of the Button that was clicked. Choose at random
among Color.RED, Color.BLUE, Color.YELLOW, etc. To change the color of the
Button, call setTextColor on the Button that is passed to the event handler. However, note
that although Button has a setTextColor method, View (the parent class of Button) does
not. So, you have to cast the View to Button before calling setTextColor.
cast your view by button and find its Id by using findview_by_id , then set the color...
(Button)view.findviewbyid(R.id.btn_id).setTextColor();
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_stack);
mainView=(RelativeLayout)findViewById(R.id.rel);
final Button redButton=new Button(this);
redButton.setText("Click");
redButton.setTextColor(Color.RED);
redButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
redButton.setTextColor(Color.GREEN);
}
});
mainView.addView(redButton);
}
I am trying to change the text color of button on click event. But while the button click event is fired, button goes missing. Code mentioned below.
Button design in Layout XML file
<Button
android:id="#+id/btnCategory1"
android:background="#000000"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#FFFFFF"
android:layout_margin="10dp"
>
</Button>
Activity.java file
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_expense);
btnType1 = (Button)findViewById(R.id.btnCategory1);
btnType1.setOnClickListener(this);
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(v == (View)btnType1)
{
btnType1.setTextColor(R.color.darkorange);
}
}
Tried the below Option also. Still Button Goes missing. Log statement is fired successfully.
btnType1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Log.v("AAAAAAAAAAA","BBBBBBBBBBB");
// TODO Auto-generated method stub
btnType1.setTextColor(R.color.orange);
}
});
If someone can find the reason, kindly share it.
You cannot use just the R.color integer when calling setTextColor. You need to call getResources().getColor(R.color.YOURCOLOR) to set a color properly.
Make your button as below
Button bOne = (Button) findViewById(R.id.btnCategory1);
bOne.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
bOne.setTextColor(getResources().getColor(R.color.YOURCOLOR));
}
});
Hmmmmm. I'm not seeing a good reason as to why that would happen.
I do think that there is maybe a better/cleaner way to do something so simple, and so I'll tell you it - go ahead and try it. This was should work.
Get rid of the btnType1.setOnClickListener(this); line from your java.
Then, go into your xml and add this to your button:
android:onClick="methodName"
Now, if you go into your java and create a method called methodName that takes a view as an argument:
public void methodName(View v) {
btnType1.setTextColor(R.color.darkorgange);
}
The color should be updated!
EDIT: Just looked again and the reason the previous code wasn't working was because you were trying to update btnType2, not btnType1. Still, try the method I just gave you. It is good practie, and a cleaner and easier way to do things for the future.
EDIT2:
All right, the mystery is solved. Here is your issue. When you do set color, you need to pass in the actual color, not just the id. Here is what you need to change that line to:
btnType1.setTextColor(getResources().getColor(R.color.darkorange));
I use greendroid to implement to actionbar under api 11.
Now i have a strange behaviour in my MainView (the startview works well)
public class MainView extends GDActivity {
private boolean ison = false;
private FinderThread finder;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
//this.getActionBar().removeViewAt(0);
setActionBarContentView(R.layout.mainlayout);
getActionBar().setBackgroundColor(Color.parseColor("#bf27c3"));
setTitle("TEST");
setTitleColor(Color.WHITE);
addActionBarItem(getActionBar().newActionBarItem(NormalActionBarItem.class).setDrawable(R.drawable.person));
Looking:
The Actionbar text is empty and no home button. please help
You can try to set the Title and the Color of the Title with
getActionBar().setTitle("Title")
The same for the color. Try also to set the color via an RGB value.
I can't promise that this will work, because i don't use greendroid for my actionbars. But i understand that you don't use actionbarsherlock + greendroid because they are only compatible with a trick (a bit hacking xD)
I use following code :
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(android.R.style.Theme_Wallpaper);
setContentView(R.layout.main);
}
But it does nothing!
How can I apply Theme.Wallpaper at runtime on android?
It works when you call the setTheme() method even before the call to the constructor of your parent class (i.e. before super.onCreate(...)).
The following works for me:
public void onCreate(Bundle savedInstanceState) {
setTheme(android.R.style.Theme_Wallpaper);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
However, it's not perfect: when launching the activity, the shown animation still belongs to the default theme -> a black screen fades in. After the animation finishes, the wallpaper theme is shown.
If you want to have a wallpaper-themed fade-in animation, you have to use the declaration in your AndroidManifest.xml
I have a TextView .I am using it like a link by using
t2.setMovementMethod(LinkMovementMethod.getInstance())
for this textview in .java files so that it blinks when I clicks, but I want the color of textview to be changed when clicked. I used
t2.setLinkTextColor(0xff0000)
but does not work. my code is as follows:
public class TextHyperLink extends Activity implements OnClickListener
{
/** Called when the activity is first created. */
TextView t2;
#Override public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
t2 = (TextView) findViewById(R.id.text2); t2.setMovementMethod(LinkMovementMethod.getInstance());
t2.setLinkTextColor(0xff0000);
t2.setOnClickListener(this);
}
public void onClick(View arg0) {
// TODO Auto-generated method stub
if(arg0==t2)
{
// t2.setColor()
// System.out.println("Link TextViewwwwww");
}
}
}
my xml
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/text2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="#string/link_text_manual"
android:textColorLink="#FFFF00"
/>
Can any one help me in solving this issue.?
The obvious answer is that you aren't calling setLinkTextColor() in the onClick method and when you add it if you want the color to change it has to be a different color than 0xff000.