i want to change icon when click on tabhost
below is the source code
private void setTabs() {
addTab("Home", TabHome.class, R.drawable.home);
addTab("Performers", TabPerformers.class, R.drawable.performers);
addTab("Tickets", TabTickets.class, R.drawable.tickets);
addTab("Info", TabInfo.class, R.drawable.info);
}
private void addTab(String labelId, Class<?> c, int drawableId) {
tabHost = getTabHost();
Intent intent = new Intent(this, c);
TabHost.TabSpec spec = tabHost.newTabSpec("tab" + labelId);
tabIndicator = LayoutInflater.from(this).inflate(R.layout.tab_indicator, getTabWidget(), false);
icon = (ImageView) tabIndicator.findViewById(R.id.icon);
icon.setImageResource(drawableId);
spec.setIndicator(tabIndicator);
spec.setContent(intent);
tabHost.addTab(spec);
}
i want to change tab's icon when user press tab for that i have used below tabhost event
tabHost.setOnTabChangedListener(new OnTabChangeListener() {
#Override
public void onTabChanged(String tabId) {
if (tabId.equals("tabHome")) {
but could not success
there is also a tab_indicater.xml file but from that only background will be change not icon
below is the xml code
<?xml version="1.0" encoding="utf-8"?>
<!-- Non focused states -->
<item android:drawable="#drawable/tab_unselected" android:state_focused="false" android:state_pressed="false" android:state_selected="false"/>
<item android:drawable="#drawable/tab_bg_selector" android:state_focused="false" android:state_pressed="false" android:state_selected="true"/>
<!-- Focused states -->
<item android:drawable="#drawable/tab_bg_selector" android:state_focused="true" android:state_pressed="false" android:state_selected="false"/>
<item android:drawable="#drawable/tab_bg_selector" android:state_focused="true" android:state_pressed="false" android:state_selected="true"/>
<!-- Pressed -->
<item android:drawable="#drawable/tab_bg_selector" android:state_pressed="true" android:state_selected="true"/>
<item android:drawable="#drawable/tab_press" android:state_pressed="true"/>
below is the screen shot
when we click on any one tab it's icon should be change like here it must become orange..
can any body help me...
There's no straightforward way to change the TabSpec icon. You have to put your icons in the selector drawables.
Related
I am trying to implement shared animation transition when someone clicks on recycler view item and navigate to detail activity.I want to show effect on image view when its size increases in detail activity.There is no transition effect is showing.
Below is my code:
themes.xml
<style name="Theme.ITunes" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">#color/purple</item>
<item name="colorPrimaryVariant">#color/purple_dark</item>
<item name="colorOnPrimary">#color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">#color/teal_200</item>
<item name="colorSecondaryVariant">#color/teal_700</item>
<item name="colorOnSecondary">#color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
<item name="android:windowContentTransitions">true</item>
</style>
item_layout.xml
<ImageView
android:layout_width="200dp"
android:layout_height="170dp"
android:id="#+id/trackImg"
android:scaleType="fitXY"
android:transitionName="imageTransition"/>
activity_video_detail.xml
<ImageView
android:layout_width="match_parent"
android:layout_height="250dp"
android:id="#+id/imgDetail"
android:scaleType="fitXY"
android:transitionName="imageTransition"/>
VideoAdapter.class
holder.itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(context, VideoDetail.class);
i.putExtra("name",model.getTrackName());
i.putExtra("image",model.getArtworkUrl100());
ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation((Activity) context,holder.trackImg,"transition");
context.startActivity(i,options.toBundle());
}
});
VideoDetail.class
#Override
public boolean onOptionsItemSelected(#NonNull MenuItem item) {
if(item.getItemId() == android.R.id.home){
onBackPressed();
}
return super.onOptionsItemSelected(item);
}
#Override
public void onBackPressed() {
supportFinishAfterTransition();
}
What can I try to resolve this?
The string passed to makeSceneTransitionAnimation should match transitionName in the receiving activity, so use imageTransition instead of transition
ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation((Activity) context,holder.trackImg,"imageTransition");
It's also a good idea to use string resources to get rid of magic strings
I'm trying to display SplashScreen in my App. The code is the same that all tutorials or documentations but my problem is with icon, i put the default icon from mipmap but it looks like this
when i use any pic or icon is the same, how can i control the size?, because the default icon has the correct size.
The code
xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/colorPrimaryDark" /><!-- color de fondo -->
<item>
<bitmap
android:gravity="center"
android:src="#mipmap/ic_launcher" /> <!-- imagen centrada -->
</item>
style.xml
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">#mipmap/ic_launcher</item>
</style>
Activity
public class SplashActivity extends AppCompatActivity {
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(this, LoginActivity.class);
startActivity(intent);
finish();
}
}
I am trying to apply custom color in AlertDialogue. Its changing text color as well background color in it but not changing SingleChoiceItems text color. You can see it black color in it with page number like below image.
I am using style like below code
<style name="AlertDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="android:textColor">#color/TextColorLite</item>
<item name="android:background">#color/colorPrimaryDarkLite</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">?attr/MainAccentColor</item>
<item name="android:buttonBarButtonStyle">#style/DialogButtonStyle</item>
</style>
<style name="DialogButtonStyle" parent="#style/Widget.AppCompat.Button.ButtonBar.AlertDialog">
<item name="android:textColor">?attr/TextColor</item>
<item name="android:textStyle">bold</item>
</style>
Java Code For Dialoge
AlertDialog.Builder builder = new AlertDialog.Builder(
getActivity(), R.style.AlertDialogTheme);
builder.setTitle("Go to Page:");
builder.setSingleChoiceItems(mPageOptions, mPageIndx - 1,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int item) {
mOptionDiag.dismiss();
mPageIndx = item + 1;
updateQuotesListServer();
updatePageInfo();
}
});
builder.setNegativeButton("Dismiss",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
}
});
mOptionDiag = builder.create();
mOptionDiag.show();
What I should do for change this black text color ?
Thanks
I have got solved adding this items in style.
<!--For List Text-->
<item name="textColorAlertDialogListItem">#color/TextColorLite</item>
<!--For Radio-->
<item name="android:textColorSecondary">#color/TextColorLite</item>
Thanks
In your resources folder open styles.xml and add a custom theme like for example this:
<style name="radiobuttonstyle" parent="Material.Drawable.RadioButton">
<!-- Hint color and label color in FALSE state -->
<item name="android:textColorHint">#color/md_green_900</item>
<item name="android:textSize">20sp</item>
<!-- Label color in TRUE state and bar color FALSE and TRUE State -->
<item name="colorAccent">#color/md_green_400</item>
<item name="colorControlNormal">#color/md_green_900</item>
<item name="colorControlActivated">#color/md_green_400</item>
</style>
and in your RadioButton in your layout add it as the theme of your RadioButton like this:
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/radioyes"
android:theme="#style/radiobuttonstyle"
android:text="Yes"
android:textColorLink="#color/md_light_green_900"
android:textColorHighlight="#color/md_green_900"
android:textColor="#color/md_light_green_900" />
PS: that is my own custom radio button so it should work.
I have created a custom DialogFragment like it is described in the developer guide.
Now what I am trying to do sounds simple enough, but I cannot get it to work.
I have defined: android:background="#android:color/transparent" in my layout xml which I am loading like this (in my onCreateDialog):
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
final View view = inflater.inflate(R.layout.pausedialog, null);
setStyle(STYLE_NO_FRAME, R.style.CustomDialog);
As you can see I also tried to set a custom style in the DialogFragment which is defined like this:
<style name="CustomDialog" parent="android:style/Theme.Dialog">
<item name="android:windowBackground">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:alwaysDrawnWithCache">false</item>
<item name="android:windowContentOverlay">#null</item>
</style>
And I also tried getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(0));
which leads to a null pointer exception.
I am using android.support.v4.app.DialogFragment. Can this be the cause?
Or am I doing something else wrong?
Try to set style and theme in onCreate method of your dialogFragment class implementation.
#Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
int style=DialogFragment.STYLE_NO_TITLE;
int theme=android.R.style.Theme_Translucent;
setStyle(style, theme);
}
Or
if you are using Dialog class then you can also set Style and theme on dialog instance.
This worked for me. I created a new style:
<style name="CustomDialog" parent="#android:style/Theme.Dialog">
<item name="android:windowBackground">#android:color/transparent</item>
</style>
And then set this style in my DialogFragment's onCreate() method like this:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NO_TITLE, R.style.CustomDialog);
}
This is the style I use to totally remove the Dialog`s background.-
<style name="Theme.Dialog" parent="#android:style/Theme.Translucent.NoTitleBar">
<item name="android:windowFrame">#null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
<item name="android:windowNoTitle">true</item>
<item name="android:backgroundDimEnabled">true</item>
</style>
As for the Dialog creation, you're creating a DialogBuilder but then you manually inflate a view, I guess that's the problem. Try this instead.-
AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.customTheme));
AlertDialog dialog = builder.create();
dialog.show();
EDIT
Another approach is extending AlertDialog.-
public class CustomDialog extends AlertDialog {
public DialogParent(Context context) {
super(context, R.style.CustomDialog);
setContentView(R.layout.pausedialog);
// More initialization stuff
}
}
And then 'manually' instantiate it.-
AlertDialog dialog = new CustomDialog(getActivity());
dialog.show();
How can i show a button as it is pressed whenever the activity is created and UI is shown to user in Android?
This should be okay:
#Override
public void onStart(){
super.onStart();
Button button = (Button) findViewById(R.id.test_button);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Log.i(TAG, "Clicked");
}
});
// This will NOT trigger the onClickListener!
button.setPressed(true);
}
You should use the button selector state like the following code i.e(res/drawable/button.xml)
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="#drawable/button_add_to_favorites_active">
</item>
<item android:state_focused="true" android:drawable="#drawable/button_add_to_favorites_active">
</item>
<item android:drawable="#drawable/button_add_to_favorites_active"> //Here set the drawable looks like pressed one.
</item>
</selector>