пытаюсь применить фон к кнопке описал данный фон в папке res/drawable. Код фона:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#FFFFFF"/>
</shape> </item> <item android:top="1dp">
<shape android:shape="rectangle"> <solid android:color="#2D2D2D"/>
</shape>
</item>
</layer-list>
Применяю фон к кнопке следующим образом: btnAnswer1.setBackground(Drawable.createFromPath("@drawable/btn_top_border"));
Ошибки не возникает, но фон кнопки в приложении отличается от того, который я пытаюсь выставить.
Код метода onCreate:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ct1 = (ConstraintLayout) findViewById(R.id.cl1);
btnSound = (ImageButton) findViewById(R.id.btnSound);
btnMenu = (ImageButton) findViewById(R.id.btnMenu);
tvLearningWords = (TextView) findViewById(R.id.tvLearningWords);
tvTranscription = (TextView) findViewById(R.id.tvTranscription);
setTitle("Новые слова");
btnAnswer1 = (Button) findViewById(R.id.btnAnswer1);
btnAnswer2 = (Button) findViewById(R.id.btnAnswer2);
btnAnswer3 = (Button) findViewById(R.id.btnAnswer3);
btnAnswer4 = (Button) findViewById(R.id.btnAnswer4);
btnAnswer5 = (Button) findViewById(R.id.btnAnswer5);
btnSound.setOnClickListener(this);
btnMenu.setOnClickListener(this);
btnAnswer1.setOnClickListener(this);
btnAnswer2.setOnClickListener(this);
btnAnswer3.setOnClickListener(this);
btnAnswer4.setOnClickListener(this);
btnAnswer5.setOnClickListener(this);
SharedPreferences sp = getSharedPreferences(MY_SETTINGS, Context.MODE_PRIVATE);
boolean hasVisited = sp.getBoolean("hasVisited", false);
themen = sp.getString("themen", "Night");
mDBHelper = new DatabaseHelper(this);
mDb = mDBHelper.getWritableDatabase();
btnAnswer1.setBackground(Drawable.createFromPath("@drawable/btn_top_border"));
if (!hasVisited) {
writeFile();
readFile();
startActivity(new Intent(this, FirstStartActivity.class));
SharedPreferences.Editor e = sp.edit();
e.putBoolean("hasVisited", true);
e.commit();
}
}