Hi I have 1 activity with 3 buttons,I have now created the ability to change the theme app, and up here all okay but I do not know how to go from buttoshape.xml to buttoshape_blue.xml
This is my theme:
<resources>
<style name="AppTheme.Blue" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/primaryColor_blue</item>
<item name="colorPrimaryDark">#color/primaryColorDark_blue</item>
<item name="colorAccent">#color/primaryAccent_blue</item>
<item name="backgroundColor">#color/bianco</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.Red" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/primaryColor_red</item>
<item name="colorPrimaryDark">#color/primaryColorDark_red</item>
<item name="colorAccent">#color/primaryAccent_red</item>
<item name="backgroundColor">#color/bianco</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
this my button in xml
<Button
android:id="#+id/magic_item"
android:text="Magic Item"
android:textColor="#FFFFFF"
android:textSize="25dp"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#drawable/buttonshape"
android:shadowColor="#A8A8A8"
android:shadowDx="0"
android:shadowDy="0"
android:shadowRadius="5"
/>
and this is my buttonshape.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<corners
android:radius="14dp"
/>
<gradient
android:angle="45"
android:centerX="90%"
android:centerColor="#ec2127"
android:startColor="#CC1414"
android:endColor="#FFFFFF"
android:type="linear"
/>
<padding
android:left="0dp"
android:top="0dp"
android:right="0dp"
android:bottom="0dp"
/>
<size
android:width="270dp"
android:height="60dp"
/>
<stroke
android:width="3dp"
android:color="#FFFFFF"
/>
my Utility
public class Utility {
public static void setTheme(Context context, int theme) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
prefs.edit().putInt(context.getString(R.string.prefs_theme_key), theme).apply();
}
public static int getTheme(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
return prefs.getInt(context.getString(R.string.prefs_theme_key), -1);
}
}
and BaseActivity
public class BaseActivity extends AppCompatActivity {
private final static int THEME_BLUE = 1;
private final static int THEME_RED = 2;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
updateTheme();
}
public void updateTheme() {
if (Utility.getTheme(getApplicationContext()) <= THEME_BLUE) {
setTheme(R.style.AppTheme_Blue);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
getWindow().setStatusBarColor(getResources().getColor(R.color.primaryColorDark_blue));
}
} else if (Utility.getTheme(getApplicationContext()) == THEME_RED) {
setTheme(R.style.AppTheme_Red);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
getWindow().setStatusBarColor(getResources().getColor(R.color.primaryColorDark_red));
}
}
}
}
You could create a custom theme attribute which would contain a reference to the background to use and set it to #drawable/buttonshape for AppTheme.Red and to #drawable/buttonshape_blue for AppTheme.Blue.
E.g. in values you could have an attrs.xml file in which there would be:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<attr name="buttonBackground" format="reference" />
</resources>
and in your themes.xml:
<style name="AppTheme.Blue" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/primaryColor_blue</item>
<item name="colorPrimaryDark">#color/primaryColorDark_blue</item>
<item name="colorAccent">#color/primaryAccent_blue</item>
<item name="backgroundColor">#color/bianco</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="backgroundColor">#color/bianco</item>
<item name="buttonBackground">#drawable/buttonshape_blue</item>
</style>
<style name="AppTheme.Red" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/primaryColor_red</item>
<item name="colorPrimaryDark">#color/primaryColorDark_red</item>
<item name="colorAccent">#color/primaryAccent_red</item>
<item name="backgroundColor">#color/bianco</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="buttonBackground">#drawable/buttonshape</item>
</style>
Your button in the layout file would look like this:
<Button
android:id="#+id/magic_item"
...
android:background="?attr/buttonBackground"
...
/>
Related
I'm currently using this style for my popup menu:
<style name="mainActivityTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="colorPrimary">#color/colorBlack</item>
<item name="colorPrimaryDark">#color/colorBlack</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
How ever it causes popup menus to have extra space on the top and bottom:
How do I make it so there is no extra space? Is there a certain style so that it wraps its contents?
Edit: I forgot to mention I inflate the view programmatically so that may be an issue
private void inflateMoreMenu(View view){
PopupMenu popupMenu = new PopupMenu(mContext, view);
popupMenu.inflate(R.menu.popup_menu);
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
#Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()){
case R.id.popup_menu_report:
//Inflate a layout
break;
case R.id.popup_menu_block:
//Inflate a layout
break;
}
return false;
}
});
#SuppressLint("RestrictedApi")
MenuPopupHelper menuHelper = new MenuPopupHelper(mContext, (MenuBuilder) popupMenu.getMenu(), view);
menuHelper.setForceShowIcon(true);
menuHelper.show();
}
XML for popup_menu:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/popup_menu_report"
android:title="Report"
android:icon="#drawable/icon_messages_report"/>
<item
android:id="#+id/popup_menu_block"
android:title="Block"
android:icon="#drawable/icon_alertdialog_block"/>
</menu>
For the OverflowMenu you can define in your app theme the actionOverflowMenuStyle attribute.
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight">
<item name="actionOverflowMenuStyle">#style/popupOverflowMenu</item>
</style>
With:
<style name="popupOverflowMenu" parent="#style/Widget.MaterialComponents.PopupMenu.Overflow">
<item name="android:popupBackground">#drawable/my_mtrl_popupmenu_background</item>
</style>
The drawable/my_mtrl_popupmenu_background.xml file:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="?attr/colorSurface"/>
<corners
android:bottomLeftRadius="4dp"
android:bottomRightRadius="4dp"
android:topLeftRadius="4dp"
android:topRightRadius="4dp"/>
</shape>
It the original file there is the padding:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="?attr/colorSurface"/>
<corners
..../>
<padding
android:bottom="8dp"
android:top="8dp"/>
</shape>
For a popup you can use:
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight">
<item name="popupMenuStyle">#style/popupMenu</item>
</style>
<style name="popupMenu" parent="#style/Widget.MaterialComponents.PopupMenu">
<item name="android:popupBackground">#drawable/my_mtrl_popupmenu_background</item>
</style>
As u can see there is some text missing in some CardView
I am trying to simply make TextView appear inside a CardView.All I need to do is make texts appear inside the CardView.The CardView appear, but some CardView do not show any text inside them.
item_names.xml
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:cardCornerRadius="5dp"
android:elevation="5dp"
android:layout_margin="5dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/numberCount"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" />
<TextView
android:id="#+id/tvName"
android:layout_below="#+id/numberCount"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" />
<TextView
android:id="#+id/arabicName"
android:layout_below="#+id/tvName"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" />
<TextView
android:id="#+id/meaning"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/arabicName"
android:gravity="center"/>
</RelativeLayout>
activity_allah_names.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:fitsSystemWindows="true"
tools:context="com.islamiclearn.namesofallah.activity.AllahNamesActivity">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/ad_view1"
android:layout_alignParentTop="true"
android:id="#+id/rcv"/>
<com.google.android.gms.ads.AdView
android:id="#+id/ad_view1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adSize="SMART_BANNER"
ads:adUnitId="#string/banner_ad_unit_id"
android:layout_alignParentBottom="true"/>
AllahNamesActivity.java
public class AllahNamesActivity extends AppCompatActivity {
private List<Names> list;
private RecyclerView mRecyclerView;
private AdView mAdView1;
/*
Intent communicate b/w Android components like Activity,
Service, Broadcast
*/
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_allah_names);
MobileAds.initialize(this, "ca-app-pub-3940256099942544~3347511713");
mAdView1 = (AdView) findViewById(R.id.ad_view1);
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.build();
// Start loading the ad in the background.
mAdView1.loadAd(adRequest);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mRecyclerView = (RecyclerView) findViewById(R.id.rcv);
getNames();
mRecyclerView.addOnItemTouchListener(new RecyclerItemClickListener(this, new RecyclerItemClickListener.OnItemClickListener() {
#Override
public void onItemClick(View view, int position) {
Intent intent = new Intent(AllahNamesActivity.this, SecondActivity.class);
Bundle bundle = new Bundle();
bundle.putInt("Position", position);
bundle.putParcelableArrayList("LIST", (ArrayList<Names>) list);
intent.putExtras(bundle);
startActivity(intent);
}
}));
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
finish();
}
return super.onOptionsItemSelected(item);
}
private void getNames() {
new AsyncTask<Void, Void, List<Names>>() {
#Override
protected List<Names> doInBackground(Void... params) {
return fillArray();
}
#Override
protected void onPostExecute(List<Names> names) {
super.onPostExecute(names);
if (names != null && names.size() > 0) {
list = names;
mRecyclerView.setLayoutManager(new GridLayoutManager(AllahNamesActivity.this, 2));
mRecyclerView.setAdapter(new NamesAdapter(list));
}
}
}.execute();
}
private List<Names> fillArray() {
String[] arraCount = getResources().getStringArray(item_count);
String[] arra = getResources().getStringArray(names);
String[] arraArabic = getResources().getStringArray(R.array.names_arabic);
String[] arraMeaning = getResources().getStringArray(R.array.meaning);
String[] music = getResources().getStringArray(R.array.music);
List<Names> namesList = new ArrayList<>();
for (int i = 0; i < arra.length; i++) {
Names names = new Names();
names.setCount(arraCount[i]);
names.setName(arra[i]);
names.setArabicName(arraArabic[i]);
names.setMeaning(arraMeaning[i]);
int resID = getId(music[i]);
names.setResId(resID);
namesList.add(names);
}
Items items = new Items();
List<String> list = new ArrayList<>();
items.setArabicList(list);
return namesList;
}
public int getId(String resName) {
return getResources().getIdentifier(resName,
"raw", getPackageName());
}
}
arrays.xml
<resources>
<string-array name="item_count">
<item>"1"</item>
<item>"2"</item>
<item>"3"</item>
<item>"4"</item>
<item>"5"</item>
<item>"6"</item>
<item>"7"</item>
<item>"8"</item>
<item>"9"</item>
<item>"10"</item>
<item>"11"</item>
<item>"12"</item>
<item>"13"</item>
<item>"14"</item>
<item>"15"</item>
<item>"16"</item>
<item>"17"</item>
<item>"18"</item>
<item>"19"</item>
<item>"20"</item>
<item>"21"</item>
<item>"22"</item>
<item>"23"</item>
<item>"24"</item>
<item>"25"</item>
<item>"26"</item>
<item>"27"</item>
<item>"28"</item>
<item>"29"</item>
<item>"30"</item>
<item>"31"</item>
<item>"32"</item>
<item>"33"</item>
<item>"34"</item>
<item>"35"</item>
<item>"36"</item>
<item>"37"</item>
<item>"38"</item>
<item>"39"</item>
<item>"40"</item>
<item>"41"</item>
<item>"42"</item>
<item>"43"</item>
<item>"44"</item>
<item>"45"</item>
<item>"46"</item>
<item>"47"</item>
<item>"48"</item>
<item>"49"</item>
<item>"50"</item>
<item>"51"</item>
<item>"52"</item>
<item>"53"</item>
<item>"54"</item>
<item>"55"</item>
<item>"56"</item>
<item>"57"</item>
<item>"58"</item>
<item>"59"</item>
<item>"60"</item>
<item>"61"</item>
<item>"62"</item>
<item>"63"</item>
<item>"64"</item>
<item>"65"</item>
<item>"66"</item>
<item>"67"</item>
<item>"68"</item>
<item>"69"</item>
<item>"70"</item>
<item>"71"</item>
<item>"72"</item>
<item>"73"</item>
<item>"74"</item>
<item>"75"</item>
<item>"76"</item>
<item>"77"</item>
<item>"78"</item>
<item>"79"</item>
<item>"80"</item>
<item>"81"</item>
<item>"82"</item>
<item>"83"</item>
<item>"84"</item>
<item>"85"</item>
<item>"86"</item>
<item>"87"</item>
<item>"88"</item>
<item>"89"</item>
<item>"90"</item>
<item>"91"</item>
<item>"92"</item>
<item>"93"</item>
<item>"94"</item>
<item>"95"</item>
<item>"96"</item>
<item>"97"</item>
<item>"98"</item>
<item>"99"</item>
</string-array>
<string-array name="names">
<item>Ar-Rahman</item>
<item>\'Ar-Rahim</item>
<item>Al-Malik</item>
<item> Al-Quddus</item>
<item>As-Salam</item>
<item>Al-Mu\'min</item>
<item>Al-Muhaymin</item>
<item>Al-Aziz</item>
<item>Al-Jabbar</item>
<item>Al-Mutakabbir</item>
<item>Al-Khaliq</item>
<item> Al-Bari\'</item>
<item>Al-Musawwir</item>
<item>Al-Ghaffar</item>
<item>Al-Qahhar </item>
<item>Al-Wahhab</item>
<item>Ar-Razzaq</item>
<item>Al-Fattah</item>
<item>Al-\'Alim</item>
<item>Al-Qabid</item>
<item>Al-Basit</item>
<item>Al-Khafid</item>
<item>Ar-Rafi</item>
<item>Al-Mu\'izz</item>
<item>Al-Mudhill</item>
<item>As-Sami</item>
<item>Al-Basir</item>
<item>Al-Hakam</item>
<item>Al-\'Adl</item>
<item>Al-Latif</item>
<item>Al-Khabir</item>
<item>Al-Halim</item>
<item>Al-Azim</item>
<item>Al-Ghafur</item>
<item>Ash-Shakur</item>
<item>Al-Ali</item>
<item>Al-Kabir</item>
<item>Al-Hafiz</item>
<item>Al-Muqit</item>
<item>Al-Hasib</item>
<item>Al-Jalil</item>
<item>Al-Karim</item>
<item>Ar-Raqib</item>
<item>Al-Mujib</item>
<item>Al-Wasi</item>
<item>Al-Hakim</item>
<item>Al-Wadud</item>
<item>Al-Majid</item>
<item>Al-Ba\'ith</item>
<item>Ash-Shahid</item>
<item>Al-Haqq</item>
<item>Al-Wakil</item>
<item>Al-Qawiyy</item>
<item>Al-Matin</item>
<item>Al-Waliyy</item>
<item>Al-Hamid</item>
<item>Al-Muhsi</item>
<item>Al-Mubdi\'</item>
<item>Al-Mu\'id</item>
<item>Al-Muhyi</item>
<item>Al-Mumit</item>
<item>Al-Hayy</item>
<item>Al-Qayyum</item>
<item>Al-Wajid</item>
<item>Al-Majid</item>
<item>Al-Wahid</item>
<item>Al-Ahad</item>
<item>As-Samad</item>
<item>Al-Qadir</item>
<item>Al-Muqtadir</item>
<item>Al-Muqaddim</item>
<item>Al-Mu\'akhkhir</item>
<item>Al-Awwal</item>
<item>Al-Akhir</item>
<item>Az-Zahir</item>
<item>Al-Batin</item>
<item>Al-Wali</item>
<item>Al-Muta\'ali</item>
<item>Al-Barr</item>
<item>At-Tawwab</item>
<item>Al-Muntaqim</item>
<item>Al-\'Afuww</item>
<item>Ar-Ra\'uf</item>
<item>Malik-al-Mulk</item>
<item>Dhu-al-Jalal \n wa-al-Ikram</item>
<item>Al-Muqsit</item>
<item>Al-Jami\'</item>
<item>Al-Ghani</item>
<item>Al-Mughni</item>
<item>Al-Mani\'</item>
<item>Ad-Darr</item>
<item>An-Nafi\'</item>
<item>An-Nur</item>
<item>Al-Hadi</item>
<item>Al-Badi</item>
<item>Al-Baqi</item>
<item>Al-Warith</item>
<item>Ar-Rashid</item>
<item>As-Sabur</item>
</string-array>
<string-array name="names_arabic">
<item>الرحمن</item>
<item >الرحيم</item>
<item> الملك</item>
<item> القدوس</item>
<item>السلام</item>
<item>المؤمن</item>
<item >المهيمن</item>
<item >العزيز</item>
<item>الجبار</item>
<item >المتكبر</item>
<item >الخالق</item>
<item >البارئ</item>
<item >المصور</item>
<item >الغفار</item>
<item >القهار</item>
<item >الوهاب</item>
<item >الرزاق</item>
<item >الفتاح</item>
<item >العليم</item>
<item >القابض</item>
<item >الباسط</item>
<item >الخافض</item>
<item >الرافع</item>
<item >المعز</item>
<item >المذل</item>
<item >السميع</item>
<item >البصير</item>
<item >الحكم</item>
<item >العدل</item>
<item >اللطيف</item>
<item >الخبير</item>
<item >الحليم</item>
<item >العظيم</item>
<item >الغفور</item>
<item >الشكور</item>
<item >العلى</item>
<item >الكبير</item>
<item >الحفيظ</item>
<item >المقيت</item>
<item >الحسيب</item>
<item >الجليل</item>
<item >الكريم</item>
<item >الرقيب</item>
<item >المجيب</item>
<item >الواسع</item>
<item >الحكيم</item>
<item >الودود</item>
<item >المجيد</item>
<item >الباعث</item>
<item >الشهيد</item>
<item >الحق</item>
<item >الوكيل</item>
<item >القوى</item>
<item >المتين</item>
<item > الولى</item>
<item >الحميد</item>
<item >المحصى</item>
<item >المبدئ</item>
<item >المعيد</item>
<item >المحيى</item>
<item >المميت</item>
<item >الحي</item>
<item >القيوم</item>
<item >الواجد</item>
<item >الماجد</item>
<item >الواحد</item>
<item >الصمد</item>
<item >الاحد</item>
<item >القادر</item>
<item >المقتدر</item>
<item >المقدم</item>
<item >المؤخر</item>
<item >الأول</item>
<item >الأخر</item>
<item >الظاهر</item>
<item >الباطن</item>
<item >الوالي</item>
<item >المتعالي</item>
<item >البر</item>
<item >التواب</item>
<item >المنتقم</item>
<item >العفو</item>
<item >الرؤوف</item>
<item >مالك الملك</item>
<item >ذو الجلال و الإكرام</item>
<item >المقسط</item>
<item >الجامع</item>
<item >الغنى</item>
<item >المغنى</item>
<item > المانع</item>
<item > الضار</item>
<item >النافع</item>
<item > النور</item>
<item >الهادي</item>
<item >البديع</item>
<item >الباقي</item>
<item >الوارث</item>
<item > الرشيد</item>
<item > الصبور</item>
</string-array>
<string-array name="meaning">
<item >The All-Compassionate</item>
<item >The All-Merciful</item>
<item >The Absolute Ruler</item>
<item >The Pure One</item>
<item >The Source of Peace</item>
<item >The Inspirer of Faith</item>
<item >The Guardian</item>
<item >The Victorious</item>
<item >The Compeller</item>
<item >The Greatest</item>
<item >The Creator</item>
<item >The Maker of Order</item>
<item >The Shaper of Beauty</item>
<item >The Forgiving</item>
<item >The Subduer</item>
<item >The Giver of All</item>
<item >The Sustainer</item>
<item >The Opener</item>
<item >The Knower of All</item>
<item >The Constrictor</item>
<item >The Reliever</item>
<item >The Abaser</item>
<item >The Exalter</item>
<item >The Bestower of Honors</item>
<item >The Humiliator</item>
<item >The Hearer of All</item>
<item >The Seer of All</item>
<item >The Judge</item>
<item >The Just</item>
<item >The Subtle One</item>
<item >The All-Aware</item>
<item >The Forbearing</item>
<item >The Magnificent</item>
<item >The Forgiver and Hider of Faults</item>
<item >The Rewarder of Thankfulness</item>
<item >The Highest</item>
<item >The Greatest</item>
<item >The Preserver</item>
<item >The Nourisher</item>
<item >The Accounter</item>
<item >The Mighty</item>
<item >The Generous</item>
<item >The Watchful One</item>
<item >The Responder to Prayer</item>
<item >The All-Comprehending</item>
<item >The Perfectly Wise</item>
<item >The Loving One</item>
<item >The Majestic One</item>
<item >The Resurrector</item>
<item >The Witness</item>
<item >The Truth</item>
<item >The Trustee</item>
<item >The Possessor of All Strength</item>
<item >The Forceful One</item>
<item >The Governor</item>
<item >The Praised One</item>
<item >The Appraiser</item>
<item >The Originator</item>
<item >The Restorer</item>
<item >The Giver of Life</item>
<item >The Taker of Life</item>
<item >The Ever Living One</item>
<item >The Self-Existing One</item>
<item >The Finder</item>
<item >The Glorious</item>
<item >The Unique, The Single</item>
<item >The One, The Indivisible</item>
<item >The Satisfier of All Needs</item>
<item >The All Powerful</item>
<item >The Creator of All Power</item>
<item >The Expediter</item>
<item >The Delayer</item>
<item >The First</item>
<item >The Last</item>
<item >The Manifest One</item>
<item >The Hidden One</item>
<item >The Protecting Friend</item>
<item >The Supreme One</item>
<item >The Doer of Good</item>
<item >The Guide to Repentance</item>
<item >The Avenger</item>
<item >The Forgiver</item>
<item >The Clement</item>
<item >The Owner of All</item>
<item >The Lord of Majesty and Bounty</item>
<item >The Equitable One</item>
<item >The Gatherer</item>
<item >The Rich One</item>
<item >The Enricher</item>
<item >The Preventer of Harm</item>
<item >The Creator of The Harmful</item>
<item >The Creator of Good</item>
<item >The Light</item>
<item >The Guide</item>
<item >The Originator</item>
<item >The Everlasting One</item>
<item >The Inheritor of All</item>
<item >The Righteous Teacher</item>
<item >The Patient One </item>
</string-array>
<string-array name="music">
<item> rahman</item>
<item> rahim </item>
<item> malik </item>
<item> quddus </item>
<item> salam</item>
<item> mumin </item>
<item> muhaimin</item>
<item> aziz</item>
<item> jabbar</item>
<item> mutakabbir</item>
<item> khaliq</item>
<item> bari</item>
<item> musawwir</item>
<item> ghaffar</item>
<item> qahhar</item>
<item> wahhab</item>
<item> razzaq</item>
<item> fattah</item>
<item> alim </item>
<item> qabid </item>
<item> basit</item>
<item> khafid </item>
<item> rafi </item>
<item> muizz </item>
<item> mudhill </item>
<item> sami</item>
<item> basir</item>
<item> hakam</item>
<item> adl </item>
<item> latif</item>
<item> khabir</item>
<item> halim</item>
<item> azim</item>
<item> ghafur</item>
<item>shakur</item>
<item> ali</item>
<item> kabir</item>
<item>hafiz</item>
<item> muqit</item>
<item> hasib</item>
<item> jalil</item>
<item> karim</item>
<item> raqib</item>
<item> mujib</item>
<item> wasi</item>
<item> hakim</item>
<item> wadud</item>
<item> majeed</item>
<item> baith</item>
<item> shahid</item>
<item> haqq</item>
<item> wakil</item>
<item> qawi</item>
<item> matin</item>
<item> wali</item>
<item> hamid</item>
<item> muhsi</item>
<item> mubdi</item>
<item> muid</item>
<item> muhyi</item>
<item> mumit</item>
<item> hayy</item>
<item> qayyum</item>
<item> wajid</item>
<item> majeed</item>
<item> wahid</item>
<item> a</item>
<item> samad</item>
<item> qadir</item>
<item> muqtadir</item>
<item> muqaddim</item>
<item> muakhkhir2a</item>
<item> awwal</item>
<item> akhir</item>
<item> zahir</item>
<item> batin</item>
<item> wali</item>
<item> muta_ali</item>
<item> barr</item>
<item> tawwab</item>
<item> muntaqim</item>
<item> afuw</item>
<item> rauf</item>
<item> malik_ul_mulk</item>
<item> dhu_l_jalali_wal_ikram</item>
<item> muqsit</item>
<item> jami</item>
<item> ghaniy</item>
<item> mughni</item>
<item> mani</item>
<item> darr</item>
<item> nafi</item>
<item> nur</item>
<item> hadi</item>
<item> badi</item>
<item> baqi</item>
<item> warith</item>
<item>rashid</item>
<item>sabur</item>
</string-array>
Probably the problem is with your arrays, you need to debug to check. You can post your arrays.
I want the floating label of TextInputLayouts to change colour (e.g. to red) when there is an error. I can change the colour of the error text, but it has no effect on the appearance of the floating label (unlike someone in some other thread claimed). I couldn't use selectors for the hint colour to solve this problem either, as there does not seem to be a state defined for errors. Does anyone have any idea how to do this without having to manually program the change on error events/create a new java class (with EditText as parent)?
Here are the stylings I defined:
<style name="EditTextFloatingLabel" parent="#android:style/TextAppearance">
<item name="android:textSize">#dimen/textsize_caption_small</item>
<item name="android:layout_marginBottom">8dp</item>
<item name="android:textColor">#color/input_text_color</item>
</style>
<style name="EditTextErrorText" parent="#android:style/TextAppearance">
<item name="android:textColor">#color/error_color</item>
</style>
<style name="EditTextLayout">
<item name="android:textColorHint">#color/placeholder_color</item>
<item name="android:background">#drawable/input_field_background</item>
<item name="android:paddingBottom">#dimen/default_margin_bottom</item>
<item name="android:paddingStart">#dimen/default_margin_left</item>
<item name="android:paddingEnd">#dimen/default_margin_right</item>
</style>
<style name="EditTextTheme">
<item name="android:imeOptions">actionDone</item>
<item name="android:maxLines">1</item>
<item name="colorControlNormal">#color/primary_line_color</item>
<item name="colorControlActivated">#color/nordea_blue</item>
<item name="android:colorControlHighlight">#color/error_color</item>
<item name="android:textColorPrimary">#color/input_field_text</item>
<item name="android:textSize">#dimen/textsize_caption</item>
<item name="android:textColorHint">#color/placeholder_color</item>
</style>
<style name="EditText">
<item name="android:theme">#style/EditTextTheme</item>
<item name="android:textCursorDrawable">#drawable/cursor_blue</item>
<item name="android:paddingTop">#dimen/default_padding_top</item>
<item name="android:paddingStart">#dimen/payment_text_input_padding</item>
</style>
Usage:
<android.support.design.widget.TextInputLayout
android:id="#+id/input_field_error_wrapper_light"
style="#style/EditTextLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="#dimen/testlogin_text_input_end_padding"
android:layout_marginStart="#dimen/testlogin_text_input_start_padding"
android:paddingTop="#dimen/default_padding_top"
app:hintTextAppearance="#style/EditTextFloatingLabel"
app:errorTextAppearance="#style/EditTextErrorText"
app:errorEnabled="true">
<EditText
android:id="#+id/input_field_light_error"
style="#style/EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#Input Field Disabled Light"
android:imeOptions="actionDone"
/>
</android.support.design.widget.TextInputLayout>
And this is what I see:
As I needed to perform some other actions as well when the layout was in error state, I decided to go with the solution of creating a custom error state and a custom TextInputLayout which can enter this state.
Code:
Defining the new error state in res/values/attrs.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
...
<!-- custom states -->
<declare-styleable name="ErrorState">
<attr name="state_error" format="boolean" />
</declare-styleable>
</resources>
ErrorStateTextInputLayout class:
public class ErrorStateTextInputLayout extends TextInputLayout {
private boolean hasError = false;
private static final int[] ERROR_STATE = new int[]{R.attr.state_error};
public ErrorStateTextInputLayout(Context context) {
super(context);
}
public ErrorStateTextInputLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ErrorStateTextInputLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
#Override
protected int[] onCreateDrawableState(int extraSpace) {
int[] state = super.onCreateDrawableState(extraSpace + 1);
if (hasError) {
mergeDrawableStates(state, ERROR_STATE);
}
return state;
}
#Override
public void setError(#Nullable CharSequence error) {
if (error == null) {
setHasError(false);
} else {
setHasError(true);
}
super.setError(error);
}
public void setHasError(boolean error) {
this.hasError = error;
refreshDrawableState();
}
}
Selector for setting the hint text colour:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:color="#color/disabled_text_color" android:state_enabled="false" />
<item android:color="#color/error_color" app:state_error="true" />
<item android:color="#color/input_text_color" android:state_focused="true" />
<item android:color="#color/placeholder_color" />
</selector>
This blog post helped me a lot: http://code.neenbedankt.com/example-of-custom-states-in-android-components/
Try this..solid_red floating color.....
<style name="TextLabelInput" parent="TextAppearance.AppCompat">
<!-- Hint color and label color in FALSE state -->
<item name="android:textColorHint">#color/solid_red</item>
<item name="android:textSize">16sp</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">#color/solid_red</item>
<item name="android:duration">200</item>
<item name="android:textColorHighlight">#color/solid_red</item>
<!-- Label color in TRUE state and bar color FALSE and TRUE State -->
<item name="colorAccent">#color/solid_red</item>
<item name="colorControlNormal">#color/solid_red</item>
<item name="colorControlActivated">#color/solid_red</item>
<item name="colorPrimary">#color/solid_red</item>
<item name="colorPrimaryDark">#color/solid_red</item>
<android.support.design.widget.TextInputLayout
android:id="#+id/input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
app:errorTextAppearance="#style/TextLabelInput"
>
hint text color manage over your main theme
which are colorPrimary and colorAccent
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
I'm trying to customize ProgressDialog style to have something like that:
What I have:
I know how to change spinner style and color, but what I didn't understand that is: how to make rounded-corners, I'm trying to use android:radius attribute, but nothing changes, and I don't know how to decrease padding. Maybe I can do it programmatically?
<style name="TransparentProgressDialog" parent="android:Theme.Holo.Dialog">
<item name="android:alertDialogStyle">#style/CustomAlertDialogStyle</item>
<item name="android:windowBackground">#color/transparent</item>
<item name="android:textColorPrimary">#FFFFFF</item>
<item name="android:backgroundDimEnabled">false</item>
<item name="android:textColor">#FFFFFF</item>
<item name="android:textStyle">normal</item>
<item name="android:textSize">#dimen/_14sdp</item>
</style>
<style name="CustomAlertDialogStyle">
<item name="android:bottomBright">#color/transparent</item>
<item name="android:bottomDark">#color/transparent</item>
<item name="android:bottomMedium">#color/transparent</item>
<item name="android:centerBright">#color/transparent</item>
<item name="android:centerDark">#color/transparent</item>
<item name="android:centerMedium">#color/transparent</item>
<item name="android:fullBright">#color/transparent</item>
<item name="android:fullDark">#color/transparent</item>
<item name="android:topBright">#color/transparent</item>
<item name="android:topDark">#color/transparent</item>
</style>
try the below Code it works for me:
Put this XML file in drawable folder (dialog_progress_background.xml)
<corners android:radius="10dp" />
<solid android:color="#80000000" />
<padding
android:bottom="40dp"
android:left="40dp"
android:right="40dp"
android:top="40dp" />
Dailog layout (R.layout.dialog_spinner.xml)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ProgressBar
android:id="#+id/progressBar"
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/progressBar"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:text="Loading..."
android:textColor="#FFFFFF" />
</RelativeLayout>
// Class for create custom Progress Dialog
public class ProgressBuilder {
private Context context;
private Dialog dialog;
public ProgressBuilder(Context context) {
this.context = context;
}
public void showProgressDialog() {
dialog = new Dialog(context);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setBackgroundDrawable(
context.getResources().getDrawable(
R.drawable.dialog_progress_background));
dialog.setContentView(R.layout.dialog_spinner);
dialog.setCancelable(false);
dialog.show();
}
public TextView getTextView()
{
return (TextView)dialog.findViewById(R.id.textView1);
}
public Dialog getDialog()
{
return dialog;
}
public void dismissProgressDialog() {
dialog.dismiss();
}
}
And call showProgressDialog() method to show Progress Dialog
ProgressBuilder dialog=new ProgressBuilder(MainActivity.this);
dialog.showProgressDialog()
//to dismiss the progress dialog
dialog.dismissProgressDialog()
When my button disabled i need remove text shadow effect and when button enable I need add this effect again.
selector_btn.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="#drawable/btn_disabled"
android:state_enabled="false" />
<item
android:drawable="#drawable/btn_pressed"
android:state_pressed="true" />
<item
android:drawable="#drawable/btn_default" />
styles.xml
<style name="TextShadow">
<item name="android:textColor">#ffffffff</item>
<item name="android:shadowColor">#0D67B9</item>
<item name="android:shadowRadius">2.0</item>
<item name="android:shadowDy">-2.0</item>
</style>
<style name="BigButton" parent="TextShadow">
<item name="android:background">#drawable/selector_btn</item>
</style>
You have make 2 defferent styles for enable and disable condition and apply it to textview when it disable or vise versa ...
<style name="TextShadow_disable">
<item name="android:textColor">#ffffffff</item>
<item name="android:shadowColor">#0D67B9</item>
<item name="android:shadowRadius">0</item>
<item name="android:shadowDy">0</item>
</style>
<style name="TextShadow_enable">
<item name="android:textColor">#ffffffff</item>
<item name="android:shadowColor">#0D67B9</item>
<item name="android:shadowRadius">2.0</item>
<item name="android:shadowDy">-2.0</item>
</style>
textstyle = (TextView) findViewById(R.id.mytext);
textstyle.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
getTextStyle();
}
});
write down this method to check enable disable;
public void getTextStyle() {
if(textstyle.isEnabled()){
textstyle.setTextAppearance(this, R.style.TextShadow_enable);
}
else{
textstyle.setTextAppearance(this, R.style.TextShadow_disable);
}
}