2015-09-25 158 views
0

我设置了一个活动与一个的EditText和一个按钮我试图做以下的事情:用户在十六进制颜色在EditText中,按下按钮,然后NavBar/ActionBar将其颜色更改为键入的值。设置导航栏/从应用(Android)内操作栏颜色

更改我发现的应用程序中的那些内容的唯一方法是将NavBar/ActionBar的样式更改为预制的样式,但我希望能够将其设置为自定义颜色。

public class VisualTweaks extends Activity implements View.OnClickListener { 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_visual_tweaks); 

     Button colorButton = (Button) findViewById(R.id.countButton); 
     EditText colorEditText = (EditText) findViewById(R.id.colorEditText); 

     colorButton.setOnClickListener(this); 
    } 

    @Override 
    public void onClick(View v) { 
     if (android.os.Build.VERSION.SDK_INT >= 21) 
      getWindow().setNavigationBarColor(getResources().getColor(R.color.navigationbar_color)); 
    } 
} 

回答

0

这是一个快速解决方案,我发现了动作条:

getActionBar().setBackgroundDrawable(new ColorDrawable(0xff00DDED)); 
getActionBar().setDisplayShowTitleEnabled(false); 
getActionBar().setDisplayShowTitleEnabled(true); 
0
ActionBar actionBar; 

actionBar = getActionBar(); 
ColorDrawable colorDrawable = new ColorDrawable(Color.parseColor("#93E9FA"));  
actionBar.setBackgroundDrawable(colorDrawable); 

为您的导航栏也

ü相同colorDrawable使用